Java Reference
In-Depth Information
The following step enters code for the getSales() method.
To Enter Applet Code for the getSales() Method
1. Enter lines 74 through 82 as shown in Figure 4-52 on the previous page.
TextPad displays the getSales() method in the coding window (Figure 4-53).
getSales()
method
FIGURE 4-53
Coding the getCode() Method for the Applet
The getCode() method, as shown in Figure 4-54, is slightly different than
that of the application. Line 86 declares a variable named code and assigns the
initial value of 0. The getCode() method uses an if statement with the getState()
method to assess the state of each of the Checkboxes in the CheckboxGroup, one
after the other. If the getState() method evaluating the first Checkbox returns a
true value, the program sets the variable code to 1. Otherwise, the else statement
is followed by another if statement, which evaluates the state of the next
Checkbox. If the second getState() method returns a true value, the program
sets the variable code to 2. The process is repeated for the third Checkbox. The
appropriate variable code is returned to the calling init() method in line 92.
83
84
public int getCode ()
85
{
86
int code = 0;
87
if ( telephoneBox.getState ()) code = 1;
88
else
89
if ( inStoreBox.getState ()) code = 2;
90
else
91
if ( outsideBox.getState ()) code = 3;
92
return code;
93
}
FIGURE 4-54
Search WWH ::




Custom Search