Java Reference
In-Depth Information
To Enter Code to Search for the Exit and Clear Commands
1. Enter lines 132 through 147 as shown in Figure 6-22.
The TextPad window displays the actionPerformed() method header, fol-
lowed by an if statement to determine which menu command the user
clicked (Figure 6-23). If the user clicked the Exit command, the program will
terminate; if the user clicked the Clear command, the program will clear the
TextField and reset initial values.
actionPerformed()
method header
code to exit
program
code to clear
number displayed in
lcd TextField and
reset initial values
tests
for Exit
command
tests for
Clear
command
FIGURE 6-23
Even though the user cannot type into the read-only lcd TextField, request-
ing the focus in line 145 will cause the insertion point to display in the lcd
TextField as a visual reminder that the calculator is ready for the next entry.
Searching for the Copy and Paste Commands
Figure 6-24 on the next page displays the code executed if the user clicks
Copy or Paste on the Edit menu. Line 148 compares the ActionCommand stored
in the variable, arg, with the word, Copy. If a match is found, the code in lines
150 through 152 executes. The getSystemClipboard() method in line 150 is
called from within a reference to the operating system toolkit using the
getDefaultToolkit() method. The current clipboard then is named cb. It is
common to use the period (.) delimiter to link together two methods.
Using the System Clipboard
By using the clipboard, you can copy and paste data from the
calculator into most any other Windows program, or vice versa.
Be sure to paste only numeric data into the calculator program,
as text will be ignored.
 
Search WWH ::




Custom Search