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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access