// Temperature Conversion - Al Williams
import waba.ui.*;

public class Convert extends MainWindow
{
// convert buttons
Button F2C;   
Button C2F;
// labels to mark the edit fields
Label CLabel;  
Label FLabel;  
// the edit fields
Edit C;        
Edit F;

public Convert()
  {
  // set up user interface
  F2C = new Button("F->C");
  C2F = new Button("C->F");
  CLabel = new Label("Celsius");
  FLabel = new Label("Fahrenheit");
  C = new Edit();
  F = new Edit();
  CLabel.setRect(0,10,50,15);
  FLabel.setRect(0,30,50,15);
  F.setRect(55,30,40,15);
  C.setRect(55,10,40,15);
  F2C.setRect(0, this.height - 15, 40, 15);
  C2F.setRect(55, this.height - 15, 40, 15);
  add(C);
  add(F);
  add(CLabel);
  add(FLabel);
  add(F2C);
  add(C2F);
  }
  
  
  
public void onEvent(Event event)
  {
// react to button push
  if (event.type == ControlEvent.PRESSED)
    {
    if (event.target == C2F)
      {
// convert to F
      int t = waba.sys.Convert.toInt(C.getText());
      t=9*t/5+32;
      F.setText(waba.sys.Convert.toString(t));
      }
    if (event.target == F2C)
      {
// convert to C
      int t;
      t = waba.sys.Convert.toInt(F.getText());
      t=(t-32)*5/9;
      C.setText(waba.sys.Convert.toString(t));
      }
    }
  
   }
  }