import java.awt.*;
import java.awt.event.*;
public class Test extends Frame
{
public static void main(String[] args)
{
new Test();
}
public Test()
{
this.setSize(800,600);
this.addWindowListener(new WindowAdapter()//添加窗体关闭事件
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
MenuBar mb = new MenuBar();
Menu m = new Menu("文件");
MenuItem mi = new MenuItem("退出");
mi.addActionListener(new ActionListener()//为选项添加关闭事件
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
m.add(mi);
mb.add(m);
this.setMenuBar(mb);//为窗口设置菜单条;
this.setVisible(true);
}
}
MenuItem.setdispose();
button.setdispose();