package MyMenu;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MyWindowDemo
{
private Frame f;
private MenuBar mb;
private Menu fileM;
private MenuItem miLoad,miSave,miExit;
private FileDialog openDia,saveDia;
MyWindowDemo()
{
init();
}
public void init()
{
f = new Frame("my window");
f.setBounds(200,300,300,250);
mb = new MenuBar();
fileM = new Menu("文件");
miLoad = new MenuItem("打开");
miSave = new MenuItem("保存");
miExit = new MenuItem("退出");
openDia = new FileDialog(f,"我要打开",FileDialog.LOAD);
saveDia = new FileDialog(f,"我要保存",FileDialog.SAVE);
f.setMenuBar(mb);
mb.add(fileM);
fileM.add(miLoad);
fileM.add(miSave);
fileM.add(miExit);
MyEvent();
f.setVisible(true);
}
public void MyEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
miLoad.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ex)
{
openDia.setVisible(true);
}
});
miSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent exx)
{
saveDia.setVisible(true);
}
});
miExit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent exxx)
{
System.exit(0);
}
});
}
}
class MyFrame
{
public static void main(String[] args)
{
new MyWindowDemo();
}
}
|