Workshop: Handling Parameters in an Applet

The next project you'll undertake has little practical value, except perhaps as a taunting device. The ShowWeight applet takes a person's weight and displays it under several different units. The applet takes two parameters: a weight in pounds, and the name of the person who weighs that amount. The weight is used to figure out the person's weight in ounces, kilograms, and metric tons, all of which are displayed.

Create a new file with your word processor and give it the name ShowWeight.java. Enter Listing 17.3 into the file. Then save and compile the file.

Listing 17.3. The Full Text of ShowWeight.java
 1: import java.awt.*; 2: 3: public class ShowWeight extends javax.swing.JApplet { 4: float lbs = (float)0; ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.