//********************************************************************
//  Fahrenheit.java       Author: Lewis and Loftus
//
//  Demonstrates the use of GUI components.
//********************************************************************

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Fahrenheit extends Applet implements ActionListener
{
   private int APPLET_WIDTH = 200;
   private int APPLET_HEIGHT = 100;

   private Label inputLabel, outputLabel, resultLabel;
   private TextField fahrenheit;

   //-----------------------------------------------------------------
   //  Sets up the applet with its various components.
   //-----------------------------------------------------------------
   public void init()
   {
      inputLabel = new Label ("Enter Fahrenheit:");
      outputLabel = new Label ("Temperature in Celcius:");
      resultLabel = new Label ("N/A");

      fahrenheit = new TextField (5);
      fahrenheit.addActionListener (this);

      add (inputLabel);
      add (fahrenheit);
      add (outputLabel);
      add (resultLabel);

      setBackground (Color.white);
      setSize (APPLET_WIDTH, APPLET_HEIGHT);
   }

   //-----------------------------------------------------------------
   //  Performs the conversion when the enter key is pressed in
   //  the text field.
   //-----------------------------------------------------------------
   public void actionPerformed (ActionEvent event)
   {
      int fahrenheitTemp, celciusTemp;

      String text = fahrenheit.getText();

      fahrenheitTemp = Integer.parseInt (text);
      celciusTemp = (fahrenheitTemp-32) * 5/9;

      resultLabel.setText (Integer.toString (celciusTemp));
   }
}
