提供了常用的JAVA技术的示例
源代码在线查看: testmenu.java~34~
package TestMenu; import java.awt.*; import java.awt.event.*; import java.awt.Frame; import javax.swing.ImageIcon; public class TestMenu { private Frame f=new Frame("多级菜单示例"); private Menu m1=new Menu("文件"); private Menu m2=new Menu("编辑"); private Menu mhelp=new Menu("帮助"); private MenuBar mb=new MenuBar(); private MenuItem mi11=new MenuItem("新建"); private MenuItem mi12=new MenuItem("打开"); private MenuItem mi13=new MenuItem("保存"); private MenuItem mi21=new MenuItem("查找"); private MenuItem mih=new MenuItem("帮助文件"); CheckboxMenuItem mi22=new CheckboxMenuItem("工具"); public TestMenu() { m1.add(mi11); m1.add(mi12); m1.add(mi13); m1.addSeparator(); // 分 隔 符 m1.add(m2); m2.add(mi21); m2.add(mi22); f.setMenuBar(mb); // f.setIconImage(); f.setIconImage(new ImageIcon("javaIcon.gif").getImage()); mb.add(m1); mb.setHelpMenu(mhelp); mhelp.add(mih); f.setSize(200,200); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){System.exit(0);} }); f.setVisible(true); } public static void main(String[] args) { TestMenu testMenu1 = new TestMenu(); } }