- /**
- * Class for Creating a Menu Which can be added to
Other Programs
- *
- * @author T. K. Rogers
- * @version 1/22/04
- */
- import java.awt.* ;
- import java.awt.event.* ;
- import javax.swing.* ;
- public class GuiMenu
extends JMenuBar
// Inherits from JMenuBar p. 404
-
implements ActionListener // Adds an interface
-
- {
- public static JCheckBoxMenuItem option ;
- private JMenuItem about ,
- reset ,
- whoCares ;
- public GuiMenu ( ) {
-
// File menu setup
-
JMenu fileMenu = new JMenu (
"File" ) ;
-
fileMenu.setMnemonic ( 'F' ) ;
-
-
JMenu preferences = new JMenu (
"Preferences" ) ;
-
preferences.setMnemonic ( 'P' ) ;
-
option = new JCheckBoxMenuItem (
"Slow", true ) ;
-
option.setMnemonic ( 'S' ) ;
-
preferences.add (option) ;
-
-
reset = new JMenuItem ( "Reset" ) ;
-
reset.setMnemonic ( 'R' ) ;
-
reset.addActionListener ( this ) ;
-
-
fileMenu.add ( preferences ) ;
-
fileMenu.addSeparator ( ) ;
-
fileMenu.add ( reset ) ;
-
add ( fileMenu ) ;
-
-
// Help menu set up
-
JMenu helpMenu = new JMenu (
"Help" ) ;
-
helpMenu.setMnemonic ( 'H' ) ;
-
-
about = new JMenuItem ( "About" ) ;
-
about.setMnemonic ( 'A' ) ;
-
about.addActionListener ( this ) ;
-
-
helpMenu.add ( about ) ;
-
add ( helpMenu ) ;
-
-
JMenu caresMenu = new JMenu (
"Who Cares?!" ) ;
-
caresMenu.setMnemonic ( 'W' ) ;
-
-
whoCares = new JMenuItem ( "What?" ) ;
-
whoCares.setMnemonic ( 'W' ) ;
-
whoCares.addActionListener ( this ) ;
- }
-
- //Action listener for the slow and about
menu option ///////////////////
- public void actionPerformed ( ActionEvent
e ) {
- JMenuItem item =
( JMenuItem ) e.getSource ( ) ;
- if ( item ==
reset ) {
-
GraphicsDisplay.resetDot ( ) ;
- }
-
- if ( item ==
about ) {
-
showAbout ( ) ;
- }
- }
-
- public void showAbout ( ) {
-
JOptionPane.showMessageDialog ( null,
-
"This applet demonstrates many GUI and\nmenu features",
-
"About",
-
JOptionPane.PLAIN_MESSAGE ) ;
- }
- }