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){
        init(s);
        setLocation(x, y);
        setSize(w, h);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
    private void init(String s) {
        setTitle(s);
        menubar = new JMenuBar();
        menu = new JMenu("菜单");
        subMenu = new JMenu("软件项目");
        item1 = new JMenuItem();
        item1 = new JMenuItem("动画话题",new ImageIcon("src/picture/dm.png"));
        item2 = new JMenuItem("java话题",new ImageIcon("src/picture/java.png"));
        item1.setAccelerator(KeyStroke.getKeyStroke("A"));
        item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
        menu.add(item1);
        menu.addSeparator();
        menu.add(item2);
        menubar.add(menu);
        menu.add(subMenu);
        subMenu.add(new JMenuItem("汽车销售系统",new ImageIcon("src/picture/dm.png")));
        subMenu.add(new JMenuItem("农场信息系统",new ImageIcon("src/picture/java.png")));
        setJMenuBar(menubar);
        
    }
}

 

posted on 2016-05-31 12:50  王铭霞  阅读(1271)  评论(0编辑  收藏  举报