Java Reference
In-Depth Information
2. Enter lines 56 through 69 as shown in Figure 6-9 on the previous page.
The TextPad window displays the addActionListener() and
setActionCommand() methods (Figure 6-11). Both an addActionListener()
method and a setActionCommand() method are included for each of the five
menu commands.
addActionListener()
methods for each
menu item
setActionCommand()
methods for each
menu item
FIGURE 6-11
The Java API contains information about many other methods for adding
special features to menus, such as checkmarks, shortcut keys, graphics, arrows,
and submenus. Each menu command also can be enabled, disabled, and hidden
depending on actions taken by the user or the program.
Initializing the Calculator Variables
Figure 6-12 displays the code to set initial values for the Calculator
application. Line 71 is a TextField with a length of 20 that will display in the
North region of the interface. As noted in the requirements document in
Figure 6-2 on page 382, the user should not be allowed to enter data or change
the answers in the calculator by typing into the TextField. Line 72 uses the
setEditable() method to limit user input to button clicks. The setEditable()
method , which takes a boolean argument, is set to false. Users cannot type into
a TextField if the setEditable() method is set to false — which means the field
will be read only. Using the setEditable() method especially is effective when you
want the display to be distinctive, such as black letters on a white background, or
when a Label component does not seem appropriate or is not needed. In the
Calculator application, the TextField will represent the LCD display on a typical
calculator, and users will not be able to type into it.
 
Search WWH ::




Custom Search