Handling Parameters in an Applet

The workshop for this hour 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, which are all displayed.

Create a new empty Java file called WeightScale, enter the text of Listing 17.3 into the file, and save the file.

Listing 17.3. The Full Text of WeightScale.java

 1: import java.awt.*; 2: 3: public class WeightScale extends javax.swing.JApplet { 4:     float lbs = 0F; 5:     float ozs; 6:     float kgs; 7:     float metricTons; 8:     String name = "somebody"; 9:10:     public void init() {11:         String ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth 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.