/*
* BodyMassApplet.java
*
* Created on February 20, 2008, 10:40 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package bodymassapplet;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**
* 2/20/2008
* @author Andrew
*/

public class BodyMassApplet extends Applet implements ActionListener
{
Image logo;
int inches, pounds;
double meters, kilograms, index;

//construct components
Label companyLabel = new Label("The Sun Fitness Center Body Mass Index Calculator.");
Label heightLabel = new Label(" Enter your height to nearest inch: ");
TextField heightField = new TextField(20);
Label weightLabel = new Label("Enter your weight to nearest pound: ");
TextField weightField = new TextField(20);
Button calcButton = new Button("Calculate");
Label outputLabel = new Label(
" Click the Calculate button to see your Body Mass Index. ");

public void init()
{
setForeground(Color.red);
add(companyLabel);
add(heightLabel);
add(heightField);
add(weightLabel);
add(weightField);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
logo = getImage(getDocumentBase(),"logo.gif");
}//end of init

public void actionPerformed(ActionEvent e)
{
inches = Integer.parseInt(heightField.getText());
pounds = Integer.parseInt(weightField.getText());
meters = inches / 39.36;
kilograms = pounds /2.2;
index = kilograms / Math.pow(meters,2);
outputLabel.setText("Your BMI is "+Math.round(index)+".");
}//end of actionPerformed

public void paint(Graphics g)
{
g.drawImage(logo, 120, 150, this);
}//end of paint
}//end of BodyMassApplet class