Java Reference
In-Depth Information
Directory "Sketcher 6 using Action objects"
You can't use the array of file actions very comfortably here because of the separators. First you create
the File menu item on the menu bar and set its mnemonic as 'F' . You then call the createFileMenuAc-
tions() helper method to create the FileAction objects you use to create the menu items. You create
each menu item by passing the appropriate FileAction object to the JMenuItem class constructor. The
resulting reference you pass to the add() method for the JMenu object, fileMenu . The properties you
have set in a FileAction object determine the appearance and behavior of the menu item that you create
from it. Finally you add the menu to the menu bar.
The other two menu bars are a little different because they are going to be radio buttons. We need to ac-
cess these menus later to set the correct menu item checked, so add JMenu members to SketcherFrame
to store references to them:
private JMenu elementMenu;
// Elements
menu
private JMenu colorMenu;
// Color menu
Directory "Sketcher 6 using Action objects"
These statements can go following the definition of menuBar .
Here's the createElementMenu () method implementation:
private void createElementMenu() {
createElementTypeActions();
elementMenu = new JMenu("Elements");
// Create
Elements menu
elementMenu.setMnemonic('E');
// Create
shortcut
createRadioButtonDropDown(elementMenu, typeActions, lineAction);
menuBar.add(elementMenu);
// Add the
element menu
}
Directory "Sketcher 6 using Action objects"
This creates the menu items for element types. It uses another helper method, createRadioBut-
tonDropDown() , to create the menu items in the drop-down as radio button menu items.
The helper method code to create the menu items is as follows:
Search WWH ::




Custom Search