import java.applet.Applet;

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

/** Demo use of BarControl,
 * an extension of BarDial with user adjustments. */

public class BarDemo extends Applet
implements ActionListener
{

    private TextArea textarea;

/* 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 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 () {
	setLayout (new FlowLayout ());

        add (bc1 = new BarControl (colors, starts1));
	bc1.addActionListener (this);

/* 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));
	bc2.addActionListener (this);

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

        bc2.setMark (Color.black, 150);

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

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

    public void init () {
        System.out.println ("BarDemo init");
	textarea.append ("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 void actionPerformed (ActionEvent e) {
	textarea.append ("\n"+e);

	if (e.getSource () == bc2)
	    bc3.setBar (xcolors, starts23);

	if (e.getSource () == bc3)
	    bc2.setBar (colors, starts23);
    }

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