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: MenuFrame.java 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.