//---------- Program BMIApplet (Step 2) ------------------------//

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


/**
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *   
 *  Chapter 5
 *
 *  Program BMIApplet
 *
 * <p>
 * This applet computes the body mass index (BMI).
 * It accepts the user’s height and weight and displays
 * his/her BMI according to the formula
 *         
 *        BMI = weight / (height * height)
 *
 */
public class BMIApplet extends Applet implements ActionListener
{

//----------------------------------
//    Data Members
//----------------------------------

    /**
     * The label for heightInput TextField
     */
    private Label      heightLabel;
    
    /**
     * The label for weightInput TextField
     */
    private Label      weightLabel;
    
    /**
     * The label for displaying BMI
     */
    private Label      BMILabel; 

    /**
     * The TextField to accept the user's height
     */
    private TextField  heightInput;
    
    /**
     * The TextField to accept the user's weight
     */
    private TextField  weightInput; 

    /**
     * The Button the user clicks to compute the BMI
     */
    private Button     computeButton;


//----------------------------------
//    Constructors
//----------------------------------
                                
    /**
     * Default constructor for creating and placing GUI objects
     * on this applet.
     */
    public BMIApplet()
    {
        //create objects
        heightLabel    = new Label("Your height (in meters, e.g. 1.88):");
        heightInput    = new TextField( 15 );
  
        weightLabel    = new Label("Your weight (in kilograms, e.g. 80.5):");
        weightInput    = new TextField( 15 );
  
        computeButton  = new Button("           Compute BMI             ");
  
        BMILabel       = new Label("This is your BMI Computer.");
  
        //Place the GUI objects to the applet.
        //The order of placement is significant.
        add(heightLabel);
        add(heightInput);
  
        add(weightLabel);
        add(weightInput);
  
        add(computeButton);
  
        add(BMILabel);
  
        computeButton.addActionListener(this);
    }
    

//-----------------------------------------------------
//     Public Methods:
// 
//         void   actionPerformed   (  ActionEvent   )
//
//-----------------------------------------------------
    /**
     * Implements the abstract method defined in the interface 
     * ActionListener. 
     *
     * @param event the ActionEvent object
     *
     */
    public void actionPerformed(ActionEvent event)
    {
        
    }


}