|
|
Исходный текст программы ShowFileDialog.java
|
Оглавление |
Назад
// ==========================================
// ShowFileDialog.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.awt.*;
import java.awt.event.*;
public class ShowFileDialog
{
public static void main(String args[])
{
FrameWindow frame;
frame =
new FrameWindow("File I/O Operations");
frame.setVisible(true);
}
}
// =======================================
// Class FrameWindow
// =======================================
class FrameWindow extends Frame
implements ActionListener, WindowListener
{
TextArea ta;
MenuBar mb;
Menu mFile;
MenuItem miOpen;
MenuItem miSave;
MenuItem miExit;
FileDialog fdlg;
// ============================================
// FrameWindow
// ============================================
public FrameWindow(String szTitle)
{
super(szTitle);
setSize(400, 300);
mb = new MenuBar();
mFile = new Menu("File");
miOpen = new MenuItem("Open...");
mFile.add(miOpen);
miSave = new MenuItem("Save As...");
mFile.add(miSave);
mFile.add("-");
miExit = new MenuItem("Exit");
mFile.add(miExit);
mb.add(mFile);
miOpen.addActionListener(this);
miSave.addActionListener(this);
miExit.addActionListener(this);
setMenuBar(mb);
this.addWindowListener(this);
ta = new TextArea(10, 30);
setLayout(new BorderLayout());
add("Center", ta);
}
// ============================================
// actionPerformed
// ============================================
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(miOpen))
{
fdlg = new FileDialog(this, "Open file",
FileDialog.LOAD);
fdlg.show();
ta.append("Open: " +
fdlg.getDirectory() +
fdlg.getFile() + "\n");
}
else if(e.getSource().equals(miSave))
{
fdlg = new FileDialog(this,
"Save file as...",
FileDialog.SAVE);
fdlg.show();
ta.append("Save as: " +
fdlg.getDirectory() +
fdlg.getFile() + "\n");
}
else if(e.getSource().equals(miExit))
{
setVisible(false);
System.exit(0);
}
}
// ============================================
// windowClosing
// ============================================
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
|
|
|