import java.applet.Applet;
import java.awt.*;

/** Demo use of BarControl,
 * an extension of BarDial with user adjustments.
 * Version for 1.0.2 Java. */

public class BarDemo extends Applet
{

/* Colors for segments */

    private Color [] colors = { Color.red, Color.green, Color.blue, Color.yellow };
    private Color [] xcolors = { Color.black, Color.gray, Color.white, Color.green };

/* Start of each color segment plus one to close the last.
 * The first and last coord are not adjustable.
 * Notice we are sharing one of these arrays... */

    private float [] starts1 = { 0, 30, 120, 250, 500 };
    private float [] starts23 = { 0, 30, 120, 250, 500 };

    private TextArea textarea;
    private BarControl bc1, bc2, bc3;

/** 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 ("BarDemo");
      ff.setBounds (100, 100, 500, 400);

      BarDemo cd = new BarDemo ();
      ff.add (cd);

      cd.init ();

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

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

/** Constructor */

    public BarDemo () {

        add (bc1 = new BarControl (BarDial.HORIZONTAL, colors, starts1));

/* These two share the starts23 array to illustrate a point,
 * changes in either control will update this array,
 * not what one would normally want to do. */

        add (bc2 = new BarControl (BarDial.VERTICAL, colors, starts23));

        add (bc3 = new BarControl (BarDial.VERTICAL, xcolors, starts23));

/* Mark some value on the scale over the various ranges */

        bc2.setMark (Color.black, 150);

        add (textarea = new TextArea (12,60));

	add (new Button ("Hello"));
	add (new Button ("World"));
    }

    public void init () {
System.out.println ("BarDemo init");

	textarea.setText ("BarDemo\n");
    }

/* When either BarControl sharing starts23 changes,
 * we tell the other BarControl to show new values.
 * not what one would normally want to do. */

    public boolean action (Event evt, Object arg) {
	textarea.setText (textarea.getText ()+"\n"+evt);

	if (evt.target == bc2)
	    bc3.setBar (xcolors, starts23);

	if (evt.target == bc3)
	    bc2.setBar (colors, starts23);

	return true;
    }

}
