这是教材上关于在窗口中添加菜单,子菜单,及菜单项的一个示例,然而我敲完之后窗口并不显示,懵逼。。。下面是源代码://Example.javapublic class Example { public static void main(String args[]) { WindowMenu win = new WindowMenu("带菜单的窗口",20,30,190,200); }}//WindowMenu.javaimport java.awt.event.InputEvent;import java.awt.event.KeyEvent;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.KeyStroke;public class WindowMenu extends JFrame{ JMenuBar menuBar; JMenu menu,subMenu; JMenuItem item1,item2; public WindowMenu(){} public WindowMenu(String s,int x,int y,int w, int h) { setBounds(x,y,w,h); setVisible(ture); setDefaultCloseOperation(DISPOSE_ON_CLOSE); } void init(String s) { setTitle(s); menuBar=new JMenuBar(); menu =new JMenu(); subMenu =new JMenu("子菜单"); item1=new JMenuItem("菜单项1",new ImageIcon("a.gif")); item2=new JMenuItem("菜单项2",new ImageIcon("b.gif")); item1.setAccelerator(KeyStroke.getKeyStroke('A')); item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK)); menu.add(item1); menu.addSeparator(); menu.add(item2); menu.add(subMenu); subMenu.add(new JMenuItem("子菜单里的菜单项",new ImageIcon("c.gif"))); menuBar.add(menu); setJMenuBar(menuBar); }}请求大神指教!!!!谢谢啦。
添加回答
举报
0/150
提交
取消