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

public class Thermo extends Applet
  implements ActionListener {

  private int temp = 22;
  private Label tempDisplay;
  private Button plusButton, minusButton;
  private Panel centerPanel, southPanel;

  public void init () {

    setLayout (new BorderLayout() );

    // center panel = temperature display

    tempDisplay = new Label("00", Label.CENTER);
    Font bigFont = new Font ("Helvetica", Font.BOLD, 20);
    tempDisplay.setFont(bigFont);
    showTemp();

    centerPanel = new Panel();
    centerPanel.setLayout (new FlowLayout() );
    centerPanel.add(tempDisplay);
    add (centerPanel, "Center");

     // south panel = two buttons

    minusButton = new Button(" -1");
    minusButton.addActionListener (this);
    minusButton.setActionCommand ("minus");

    plusButton = new Button("+1");
    plusButton.addActionListener (this);
    plusButton.setActionCommand ("plus");

    southPanel = new Panel();
    southPanel.setLayout (new FlowLayout() );
    southPanel.add(minusButton);
    southPanel.add(plusButton);
    add (southPanel, "South");

    setVisible(true);
  }

  private void showTemp() {
    tempDisplay.setBackground(Color.white);
    if (temp<20) {
      tempDisplay.setForeground(Color.blue);
    }
    else if (temp>25) {
      tempDisplay.setForeground(Color.red);
    }
    else {
      tempDisplay.setForeground(Color.magenta);
    } 
    tempDisplay.setText("" + temp);
  }

  public void actionPerformed (ActionEvent e) {
    String which = e.getActionCommand();
    if ( which.equals("minus") ) {
      temp--;
    }
    else if ( which.equals("plus") ) {
      temp++;
    }
    showTemp();
  }

}

