Java Reference
In-Depth Information
To Enter Applet Code for the paint() Method
1. Enter the code for lines 120 through 125 as shown in Figure 4-60.
TextPad displays the paint() method in the coding window (Figure 4-61).
paint()
method
FIGURE 4-61
The image file is located in the Chapter04 folder of the Data Disk that
accompanies this topic; you also can contact your instructor for additional
information on how to obtain the image. Remember that the image file and the
source code file need to be in the same folder for the applet to compile and run
successfully.
Compiling and Testing the Applet
The code for the applet now is complete. You declared variables; constructed
components; and wrote code for the init(), itemStateChanged(), and several
user-defined methods that were similar to the user-defined methods in the
Commission program. Now the applet can be compiled, and then run and
tested using test data.
The following steps compile and then test the applet.
To Compile and Test the Applet
1. With the Data Disk in drive A and the image file located in the same
folder as the source code, compile the program by clicking Compile
Java on the Tools menu. If TextPad notifies you of errors, click
CommissionApplet.java in the Selector window, fix the errors, and
then compile again. When the program compiles with no errors, click
Run Java Applet on the Tools menu.
(continued)
Search WWH ::




Custom Search