import java.awt.*;

public class GUIDemo extends java.applet.Applet {

   private TextArea transcript;
   String ret;

   public void init() {
   
      setBackground(Color.white);
   
      ret = System.getProperty("line.separator");
   
      transcript = new TextArea();
      transcript.setEditable(false);
      setLayout(new GridLayout(2,1,7,7));   
      Panel top = new Panel();
      top.setLayout(new GridLayout(4,1));
      add(top);
      add(transcript);
      
      Panel line = new Panel();
      line.add(new Label("Push Button:  "));
      line.add(new Button("Click Me!"));
      top.add(line);
      
      line = new Panel();
      line.add(new Label("Checkbox:  "));
      line.add(new Checkbox("Click me!"));
      top.add(line);
      
      line = new Panel();
      line.add(new Label("Text Field:  "));
      line.add(new TextField("Click, type, press return!  "));
      top.add(line);

      line = new Panel();
      line.add(new Label("Pop-up Menu:  "));
      Choice c = new Choice();
      c.addItem("First Option");
      c.addItem("Second Option");
      c.addItem("Third Option");
      c.addItem("Fourth Option");
      line.add(c);
      top.add(line);      
   }
   
   private void post(String message) {
      transcript.appendText(message + ret);
   }
   
   public Insets insets() {
      return new Insets(7,7,7,7);
   }
   
   public boolean action(Event e, Object arg) {
      if (e.target instanceof Button)
         post("Button was clicked.");
      else if (e.target instanceof TextField)
         post("Pressed return in TextField with contents: " + arg);
      else if (e.target instanceof Checkbox) {
         if (((Boolean)arg).booleanValue())
            post("Checkbox was turned on.");
         else
            post("Checkbox was turned off.");
      }
      else if (e.target instanceof Choice)
         post("Item \"" + arg + "\" selected from pop-up menu.");
      return true;
   }
   
}
