{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

menus - JMenuItem fileExitItem = new...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Menus Menus A frame contains a menu bar The menu bar contains menus A menu contains submenus and menu items Menus Figure 7: Pull-Down Menus Menu Bars Menu bars contain menus JMenuBar menuBar = new JMenuBar(); frame. setJMenuBar(menuBar); Menus A menu contains submenus and menu items You can add menus to menu bars or other menus JMenu fileMenu = new JMenu( "File" ); menuBar.add(fileMenu); JMenu recentDocumentsMenu = new JMenu(“Recent Documents”); fileMenu.add(recentDocumentsMenu); Menu Items Add menu items and submenus with the add method: A menu item has no further submenus Menu items generate action events
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: JMenuItem fileExitItem = new JMenuItem("Exit"); fileMenu.add(fileExitItem); 2 Menu Items • Add a listener to each menu item: • Add action listeners only to menu items, not to menus or the menu bar fileExitItem.addActionListener(listener); A Sample Program • Builds up a small but typical menu • Traps action events from menu items • To keep program readable, use a separate method for each menu or set of related menus – createFaceItem : creates menu item to change the font face – createSizeItem – createStyleItem...
View Full Document

{[ snackBarMessage ]}