Java Reference
In-Depth Information
6 Creating an Applet
As Webmaster for a chain of appliance stores, you have been asked to create an
applet that will display as part of the store's e-commerce site. The applet will
calculate the annual cost of running an appliance. Using text boxes, the applet
will ask the user for (1) the cost per kilowatt-hour in cents and (2) the number
of kilowatt-hours the appliance uses in a year. Perform the following steps to
create the applet. Figure 3-58 displays the applet.
FIGURE 3-58
1. Start TextPad. Save the new document as a Java source code file on the Data
Disk using the file name KilowattApplet.
2. Begin your code by typing a block comment with the Programming
Assignment number, your name, the current date, and the program name,
KilowattApplet.java. Write a description or purpose comment.
3. Type lines of code to import all of the classes from the following packages:
java.awt, java.applet, and java.awt.event.
4. Type a class header that extends Applet and implements the ActionListener.
5. Construct the components listed in Table 3-21 on the next page.
Search WWH ::




Custom Search