Swing에 메뉴 추가

2292 단어 swing
코드의 일부만 제공:
public class MenuWindow extends FirstWindow {
	private JMenuBar  menubar;
	private JMenu menuJCource,submenuJCource,menuWindow;
	private JMenuItem[]menuJCourceItem;
	private JMenuItem menuWindowItem;
	public MenuWindow(String title,String tubiaoImageName,String bgImageName){
		super(title,tubiaoImageName,bgImageName);
		menubar=new JMenuBar();
		menuJCource=new JMenu("Java  ");
		submenuJCource=new JMenu("Java     ");
		menuWindow=new JMenu("  ");
		menuJCourceItem=new JMenuItem[4];
		menuJCourceItem[0]=new JMenuItem("Java     ",
				new ImageIcon("tubiao1.jpg"));
		menuJCourceItem[1]=new JMenuItem("   ",new ImageIcon("tubiao1.jpg"));
		menuJCourceItem[2]=new JMenuItem("   ",new ImageIcon("tubiao1.jpg"));
		menuJCourceItem[3]=new JMenuItem("Java     ",
				new ImageIcon("tubiao1.jpg"));
		menuWindowItem=new JMenuItem("     ",new ImageIcon("tubiao1.jpg"));
		menuJCourceItem[0].setAccelerator(
				KeyStroke.getKeyStroke(KeyEvent.VK_1,InputEvent.ALT_MASK));
		menuJCourceItem[3].setAccelerator(
				KeyStroke.getKeyStroke(KeyEvent.VK_3,InputEvent.ALT_MASK));
		menuJCourceItem[1].setAccelerator(
				KeyStroke.getKeyStroke(KeyEvent.VK_1,InputEvent.ALT_MASK));
		menuJCourceItem[2].setAccelerator(
				KeyStroke.getKeyStroke(KeyEvent.VK_2,InputEvent.ALT_MASK));
		menuWindowItem.setAccelerator(
				KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.ALT_MASK));
		OpenWinListener objOpenWinListener=new OpenWinListener();
		menuWindowItem.addActionListener(objOpenWinListener);
		submenuJCource.add(menuJCourceItem[1]);
		submenuJCource.add(menuJCourceItem[2]);
		menuJCource.add(menuJCourceItem[0]);
		menuJCource.addSeparator();
		menuJCource.add(submenuJCource);
		menuJCource.addSeparator();
		menuJCource.add(menuJCourceItem[3]);
		menuWindow.add(menuWindowItem);
		menubar.add(menuJCource);
		menubar.add(menuWindow);
		setJMenuBar(menubar);
		validate();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
}

좋은 웹페이지 즐겨찾기