Java Reference
In-Depth Information
6 Creating an Applet (continued)
12. Close the actionPerformed() method with a closing brace and then close the
applet class with a closing brace.
13. Compile your program by clicking Tools on the menu bar and then clicking
Compile Java.
14. In the TextPad window, click the New Document button on the Standard
toolbar. Type the code from Table 3-24 for the HTML host document.
Table 3-24
HTML Host Document Code
<HTML>
<APPLET CODE = "KilowattApplet.class" WIDTH = 430 HEIGHT = 200>
</APPLET>
</HTML>
15. Save the HTML file on the Data Disk using the file name
KilowattApplet.html.
16. Execute the program. Enter the sample data as shown in Table 3-25. Run the
program again with your own personal data.
Table 3-25
Sample Data for Appliance Energy Calculator
INPUTS
OUTPUTS
Cost per kilowatt-hour
Number of kilowatt-hours consumed
Annual cost
.086
730
$62.78
17. In the TextPad window, use the Print command on the File menu to print a
copy of the source code for your instructor; then quit TextPad.
7 Bill's Burgers
Bill's Burgers would like an applet that calculates the sales tax for their front
counter help. The applet should let the worker enter the total amount of the
customer's order and then calculate a six percent (6%) sales tax. When the
worker clicks a Calculate button, the applet should display the amount of the
customer's order, the tax, and the total of the customer's order and tax added
together. Hint: Use a method and formula similar to the one in Table 3-23.
 
Search WWH ::




Custom Search