import java.applet.Applet;

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

/** Example code shows use of WrapLayout instead of FlowLayout.
 * @author Morris Hirsch IPD */

public class WrapDemo extends Applet
{

    private Panel toolbar;

    private Checkbox
	TB_Local_CB,
	TB_Help_CB,
	TB_MinMax_CB;

    private Button
	TB_Start_B,
	TB_Incr_B,
	TB_Decr_B,
	TB_Stop_B;

    private TextArea textarea;

/** To run as an application,
 * construct it and show it in a frame.
 * This must be a static (class not instance) method,
 * because the instance won't exist until we construct it here. */

  public static void main (String []argv) {

      Frame ff = new Frame ("WrapDemo");
      ff.setBounds (100, 100, 500, 300);

      WrapDemo cd = new WrapDemo ();
      ff.add (cd);
      cd.init ();

      ff.pack ();
      ff.show ();

      cd.invalidate ();
      cd.validate ();
  }

/* Still working on this...
 * comes up with good layout,
 * still trouble on manual resize that changes wrap,
 * still need to touch it sometimes */

  public void validate () {
      if (null != toolbar)
          toolbar.invalidate ();
      if (null != textarea)
          textarea.invalidate ();
      super.validate ();
  }

    public WrapDemo () {

	setLayout (new BorderLayout ());

        add ("North", toolbar = new Panel ());

/* This will wrap the buttons if needed,
 * regular FlowLayout gets it wrong.
 * Try one and see... */

	toolbar.setLayout (new WrapLayout ());

        toolbar.add
          (TB_Start_B
          = new Button ("Start"));

        toolbar.add
          (TB_Stop_B
          = new Button ("Stop"));

        toolbar.add
          (TB_Local_CB
          = new Checkbox ("Zone"));

        toolbar.add
          (TB_Incr_B
          = new Button ("Bigger"));

        toolbar.add
          (TB_Decr_B
          = new Button ("Smaller"));

        toolbar.add
          (TB_MinMax_CB
          = new Checkbox ("Minmax"));

        toolbar.add
          (TB_Help_CB
          = new Checkbox ("Help"));

        add ("Center",
	textarea = new TextArea (12,50));
    }

    public void init () {
	textarea.append ("WrapDemo\n");
	textarea.append ("ignores all buttons\n");
    }

}
/* <IMG SRC="/cgi-bin/counter">*/
