Java Reference
In-Depth Information
The container for the top-level menu items is called a menu bar. A menu is a
collection of menu items and more menus (submenus). You add menu items and
submenus with the add method:
JMenuItem fileExitItem = new JMenuItem("Exit");
fileMenu.add(fileExitItem);
802
803
Figure 9
Pull-Down Menus
A menu item has no further submenus. When the user selects a menu item, the menu
item sends an action event. Therefore, you want to add a listener to each menu item:
fileExitItem.addActionListener(listener);
You add action listeners only to menu items, not to menus or the menu bar. When the
user clicks on a menu name and a submenu opens, no action event is sent.
Menu items generate action events.
Search WWH ::




Custom Search