import java.applet.Applet;

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

public class StarFieldDemo extends Applet
implements ActionListener
{

    public static final String VERSION_STRING = "StarFieldDemo.java 1.0 9/29/99";

    public TextArea textarea;
    public StarField starfield1, starfield2, starfield3;
    public StarField sfs [] = new StarField [5];
    public Hashtable HT;

/** 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 ("StarFieldDemo");
      ff.setBounds (20, 20, 500, 500);

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

      cd.init ();

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

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

      ShowVersion.showVersion (cd);
  }

    public StarFieldDemo () {

        HT = new Hashtable ();

	setLayout (new GridLayout (2, 2, 5, 5));

/* Construct a few starfields,
 * showing the different selection modes. */

  add (sfs[0] = new StarField (StarField.ACTION, 0, 100, -100, 100));
  add (sfs[1] = new StarField (StarField.SINGLE, 0, 100, -100, 100));
  add (sfs[2] = new StarField (StarField.MULTIPLE, 0, 100, -100, 100));

/* Listen on them -- everything is an Action */

sfs[0].addActionListener (this);
sfs[1].addActionListener (this);
sfs[2].addActionListener (this);

/* Will report events here */

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

/* Set some Colors */

sfs[0].setForeground (Color.red);
sfs[1].setForeground (Color.green);
sfs[2].setForeground (Color.blue);

sfs[1].setEnterExpand (true);

/* Add some markers to the starfields.
 * Any given marker cannot belong to more than one starfield.
 ** WHAT HAPPENS IF WE ADD ONE TWICE? */

populate (sfs[0], "One");
sfs[0].add (new StarMarker ("ACTION", "A")).setXY (50, 10);

populate (sfs[1], "Two");
sfs[1].add (new StarMarker ("SINGLE", "S")).setXY (50, 10);

populate (sfs[2], "Three");
sfs[2].add (new StarMarker ("MULTIPLE", "M")).setXY (50, 10);

    }

    protected void populate (StarField sf, String SN) {
	StarMarker sm;
	sf.add (sm = new StarMarker ("Yo")).setXY (20, 70);
	HT.put (sm, SN+"Yo");
	sf.add (sm = new StarMarker ("Java")).setXY (70, -20);
	HT.put (sm, SN+"Java");
	sf.add (sm = new StarMarker ("Hello")).setXY (30, 50);
	HT.put (sm, SN+"Hello");
	sf.add (sm = new StarMarker ("World")).setXY (50, -30);
	HT.put (sm, SN+"World");
    }

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

    public void actionPerformed (ActionEvent evt) {
	textarea.append ("\n"+evt);
	StarMarker sm = (StarMarker)evt.getSource ();
	String tag = (String)(HT.get (sm));
	textarea.append ("\n"+tag);
    }

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