Java Reference
In-Depth Information
3. Click the Yes button in the Choose File dialog box.
Applet Viewer displays the applet with no components (Figure 4-39). The
program stub has no active statements or commands.
Applet Viewer
window
Close
button
applet stub
displays no
components
FIGURE 4-39
OTHER WAYS
4. Click the Close button in the Applet Viewer title bar. If necessary, click
the Close button in the command prompt window title bar.
1. To compile, press
CTRL + 1
2. To compile at
command prompt,
type javac
CommissionApplet.
java
3. To run, press CTRL + 3
4. To run at command
prompt, type
appletviewer
CommissionApplet.
html
Declaring Variables and Constructing Colors
The code for the applet must declare the same variables as those used in the
application, along with a new variable to hold an image for the company logo.
The code also should construct a dark red color to complement the logo. All of
these variables have class scope, which means all of the methods in the applet
will have access to their stored values.
Figure 4-40 displays the variable declarations and color constructor. The
variables, dollars and answer, will store dollar amounts using the double data
type. In line 19, the variable, empCode, will hold the commission code of 1, 2, or
3 using an integer data type. Line 20 declares an Image object named dollarSign.
Line 21 constructs a Color object named darkRed. As shown in Line 21, the
Color() method takes three arguments, each of which is a number in the range
from 0 to 255 that corresponds to a specified red, green, and blue color. When
combined, these three red, green, and blue colors can create a wide range of
different colors, including darkRed.
17
//declare variables and construct a color
18
double dollars, answer;
19
int empCode;
20
Image dollarSign;
21
Color darkRed = new Color ( 160, 50, 0 ) ;
22
FIGURE 4-40
 
Search WWH ::




Custom Search