Java Reference
In-Depth Information
Coding the output() Method for the Applet
The output() method, shown in Figure 4-58, causes the output to display in
the applet. The output() method accepts the commission and sales values (line
115) from the calling method, constructs an instance of the DecimalFormat
object with a pattern of dollars and cents (line 117), and then uses the setText()
method to send the output to the Label in the applet interface (line 118).
114
115
public void output ( double commission, double sales )
116
{
117
DecimalFormat twoDigits = new DecimalFormat ( "$#,000.00" ) ;
118
outputLabel.setText ( "Your commission on sales of " + twoDigits.format ( sales ) +
" is " + twoDigits.format ( commission )) ;
119
}
FIGURE 4-58
The following step enters code for the output() method in the applet.
To Enter Applet Code for the output() Method
1. Enter the code for lines 114 through 119 as shown in Figure 4-58.
TextPad displays the output() method in the coding window (Figure 4-59).
output()
method
FIGURE 4-59
Search WWH ::




Custom Search