Menus and Toolbars


A menu presents several options in a menu bar or as a pop-up menu and is located in the expected window's title bar at the top of the screen. As you know, it enables the user to select a menu item. The user 's selection fires an action event. The following snippet is an example of using a menu:

 JMenuBar myMenuBar = new JMenuBar(); JMenu menu = new JMenu("first menu"); myMenuBar.add(menu); // the submenu "listens" for user selection JMenuItem myMenuItem = new JMenuItem("first submenu"); //actionListener was instantiated previously myMenuItem.addActionListener(actionListener); menu.add(myMenuItem); //last, add the menu bar to the frame // assume frame is initialized prviously frame.setJMenuBar(myMenuBar); 


JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
JavaT 2 Developer Exam CramT 2 (Exam CX-310-252A and CX-310-027)
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 187

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net