import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

/** demo applet:  sample pane above contains some panels and labels.

    @author CarlManning, caroma@ai.mit.edu<br>
    Copyright (c) 1999 Massachusetts Institute of Technology
 **/
public class SamplePanesApplet extends Applet {
  /** recommended size: at least 300x400 **/
  public void init() {
    populate(this);
  }
  public String toString() {
    return "SamplePanesApplet["+getSize().width+"x"+getSize().height+"]"; }

  public static void populate(Container c) { 
    if (! (c.getLayout() instanceof BorderLayout))
      c.setLayout(new BorderLayout());
    ActionListener buttonListener = new ActionListener () {
      public void actionPerformed(ActionEvent e){
	Button b = (Button)e.getSource();
	b.setBackground(b.getBackground()==Color.green? Color.yellow :
			b.getBackground()==Color.yellow? Color.red :
			Color.green);
      }};
    Panel hi = new Panel(new BorderLayout());
    hi.setName("hiPane"); hi.setBackground(Color.decode("#800000"));//maroon
    { 
      Button hwButton = new Button("Hi West");
      hwButton.addActionListener(buttonListener);
      hwButton.setName("HiWestButton");
      hi.add(hwButton, BorderLayout.WEST);
      Button heButton = new Button("Hi East");
      heButton.addActionListener(buttonListener);
      heButton.setName("HiEastButton");
      hi.add(heButton, BorderLayout.EAST);
    }
    Panel lo = new Panel(new FlowLayout());
    lo.setName("loPane"); lo.setBackground(Color.decode("#808080"));//darkgray
    {
      Button buttonF1 = new Button("Lo Flow 1");
      buttonF1.addActionListener(buttonListener);
      buttonF1.setName("LoButton1");
      lo.add(buttonF1);
      Button buttonF2 = new Button("Lo Flow 2");
      buttonF2.addActionListener(buttonListener);
      buttonF2.setName("LoButton2");
      lo.add(buttonF2);
    }      
    c.add(hi,                                          BorderLayout.NORTH);
    c.add(new Label("SamplePanesApplet Center Label"), BorderLayout.CENTER);
    c.add(lo,                                          BorderLayout.SOUTH);
  }

  /** frame to call from application, not applet.  Exits java on closing. 
   **/
  public static Frame makeFrame() { 
    Frame f = new Frame("SamplePanesFrame (Close to exit)");
    f.setName("SamplePanesFrame");
    populate(f);
    f.pack();
    f.addWindowListener(new java.awt.event.WindowAdapter() {
                          public void windowClosing(java.awt.event.WindowEvent
						    e) {
			    System.exit(0);
			  }
                        });
    return f;
  }
}
