Using Menus in an Application

Figures 22.522.6 demonstrate various menu items and how to specify special characters called mnemonics that can provide quick access to a menu or menu item from the keyboard. Mnemonics can be used with all subclasses of javax.swing.AbstractButton. Class MenuFrame (Fig. 22.5) creates the GUI and handles the menu-item events. Most of the code in this application appears in the class’s constructor (lines 34–151).

 1   // Fig. 22.5: 2   // Demonstrating menus. 3   import java.awt.Color; 4   import java.awt.Font; 5   import java.awt.BorderLayout; 6   import java.awt.event.ActionListener; 7   import java.awt.event.ActionEvent; 8   import java.awt.event.ItemListener; 9    ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.