Menu菜单,MenuBar菜单栏,MenuItem菜单项

时间:2021-12-26 10:53:54
Menu菜单,MenuBar菜单栏,MenuItem菜单项
菜单栏:
public class MenuDemo {
public static void main(String args[])
{
Frame f = new Frame("Menu菜单");
MenuBar mb = new MenuBar();
f.setMenuBar(mb);
f.setSize(150,100);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setVisible(true);
}
}

菜单,菜单栏
public class MenuDemo {
public static void main(String args[])
{
Frame f = new Frame("Menu菜单");
MenuBar mb = new MenuBar();
Menu m = new Menu("文件");
Menu m1 = new Menu("编辑");
Menu m2 = new Menu("帮助");
mb.add(m);
mb.add(m1);
mb.add(m2);
f.setMenuBar(mb);
f.setSize(150,100);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setVisible(true);
}
}
菜单项:
public class MenuDemo {
public static void main(String args[])
{
Frame f = new Frame("Menu菜单");
MenuBar mb = new MenuBar();
Menu m = new Menu("文件");
Menu m1 = new Menu("编辑");
Menu m2 = new Menu("帮助");
mb.add(m);
mb.add(m1);
mb.add(m2);
MenuItem mi1 = new MenuItem("新建");
MenuItem mi2 = new MenuItem("打开");
m.add(mi1);
m.add(mi2);
f.setMenuBar(mb);
f.setSize(150,100);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.setVisible(true);
}
}