import java.applet.Applet;

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

/** Must say what Listener interfaces we implement.
 * The ListenerAdder will do the rest. */

public class ListenerDemo extends Applet
implements ActionListener, ItemListener, AdjustmentListener
{

/* A few GUI components... */

    private Checkbox
	Mode_CB,
	Help_CB;

    private Button
	Start_B,
	Stop_B;

    private TextArea textarea;

    private TextField textfield;

    private Scrollbar VS, HS;

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

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

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

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

      ff.pack ();
  }

/** Constructor.
 * Create a few GUI components,
 * add them to this (we extend Panel),
 * then let ListenerAdder make all the connections,
 * even for components in a sub Panel. */

    public ListenerDemo () {

	setForeground (Color.red);

	setLayout (new BorderLayout ());

	add ("North", textfield = new TextField (50));

	add ("Center", textarea = new TextArea (15,60));
	textarea.setForeground (Color.blue);

	Panel BBox;
	add ("South", BBox = new Panel (new FlowLayout ()));

        BBox.add (Start_B = new Button ("Start"));
        BBox.add (Stop_B = new Button ("Stop"));
        BBox.add (new Button ("Tilt"));
        BBox.add (new Button ("Turn"));
        BBox.add (Mode_CB = new Checkbox ("Mode"));
        BBox.add (Help_CB = new Checkbox ("Help"));
	BBox.add (VS = new Scrollbar (Scrollbar.VERTICAL, 0, 50, 0, 200));
	BBox.add (HS = new Scrollbar (Scrollbar.HORIZONTAL, 0, 50, 0, 250));

	BBox.setBackground (Color.yellow);

/* Make all possible valid connections between
 * all our listener methods and all our components,
 * even for components in a sub Panel. */

        ListenerAdder.add_Listeners (this, this);

/* Because menubar is not a child-of-this the usual way,
 * need explicit mention to add listeners.
 * Applets don't have a menubar so this is commented out.
 * It would run down the menu-tree,
 * adding a listener on every menu choice.  */

      //// ListenerAdder.add_Listeners (this, menubar);

        invalidate ();
        validate ();
    }

    public void init () {
	textarea.append ("ListenerDemo\n");
    }

/** Methods required by Listeners we implement */

    public void itemStateChanged (ItemEvent e) {
	textarea.append ("\n "+e);
    }

    public void actionPerformed (ActionEvent e) {
	if (e.getSource () == Start_B)
	    textarea.append ("\nStart");

        else if (e.getSource () == Stop_B)
	    textarea.append ("\nStop");

        else
	    textarea.append ("\n "+e);
    }

    public void adjustmentValueChanged (AdjustmentEvent e) {
	textarea.append ("\n "+e);
    }
}
/* <IMG SRC="/cgi-bin/counter">*/
