Java Reference
In-Depth Information
In lines 47 and 48 of Figure 3-43 on the previous page, the result of the
getText() method is wrapped inside the parseInt() method, which means that
after Java gets the text from the TextField, it immediately is converted to an inte-
ger. The formulas are calculated in lines 49 through 51, and then the answer is
sent back to the applet via the setText() method. The setText() method does
just the opposite of the getText() method: it assigns the caption or String to an
object. In line 52, for example, the setText() method assigns the output message
to the outputLabel component. The getText() and setText() methods can be used
with both Labels and TextFields, as well as with other text-based objects in the
java.awt and javax.swing packages.
The following step enters the code for the actionPerformed() method used
to handle the click event.
To Code the actionPerformed() Method
1. With the insertion point on line 44, enter the code as shown in
Figure 3-43 on the previous page.
The actionPerformed() method code is entered (Figure 3-44).
coding
window
scrolled
actionPerformed()
method executed
when calcButton clicked
actionPerformed
code entered
getText() methods
retrieve text from
TextField components
formulas to
calculate BMI
setText() method
assigns output to
Label component
FIGURE 3-44
Search WWH ::




Custom Search