Java Reference
In-Depth Information
The addActionListener() method in lines 50, 63, 75, 82, and 89 causes the
click of the menu command to trigger the corresponding action event. Recall
that the self-referential keyword, this, connects the ActionListener to the object
itself rather than activating some other object's click event.
In line 91, the return statement is used to return the constructed JMenuBar
item to the calling method.
The following step enters code for the createMenuBar() method.
To Code the createMenuBar() Method
1. Enter the code from Figure 7-17 on page 450.
TextPad displays the code for the createMenuBar() method (Figure 7-18).
code to create
menu structure
FIGURE 7-18
The add() method in lines 43, 48, 56, 61, 68, 73, 80, and 87 takes the object
listed in the method argument and adds it to the menu system, just as it did in
its AWT counterpart. For example, in line 48, the Exit command is added to the
File menu when the mnuFileExit object is added to mnuFile. It is common prac-
tice to name JMenu and JMenuItem objects with the prefix, mnu, followed by
the command's location and keyword.
Search WWH ::




Custom Search