//******************************************************************************
// Test.java:	Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;

//==============================================================================
// Main Class for applet Test
//
//==============================================================================
public class Test extends Applet
{

	// set up size of simulation

	int NumberOfThings = 5;

        // create an array of things 

	Thing[] thingArray = new Thing[NumberOfThings];

	// some constants for offsetting the display

	int xDispOff = 100;
	int yDispOff = 100;

	// setting for time sampling

	double dTimeIncrement = 1.0;


	// Test Class Constructor
	//--------------------------------------------------------------------------
	public Test()
	{
		// TODO: Add constructor code here
	
	}

	// APPLET INFO SUPPORT:
	//		The getAppletInfo() method returns a string describing the applet's
	// author, copyright date, or miscellaneous information.
    //--------------------------------------------------------------------------
	public String getAppletInfo()
	{
		return "Name: Test\r\n" +
		       "Author: Eric Grimson\r\n" +
		       "Created with Microsoft Visual J++ Version 1.0";
	}


	// The init() method is called by the AWT when an applet is first loaded or
	// reloaded.  Override this method to perform whatever initialization your
	// applet needs, such as initializing data structures, loading images or
	// fonts, creating frame windows, setting the layout manager, or adding UI
	// components.
    //--------------------------------------------------------------------------
	public void init()
	{
        // If you use a ResourceWizard-generated "control creator" class to
        // arrange controls in your applet, you may want to call its
        // CreateControls() method from within this method. Remove the following
        // call to resize() before adding the call to CreateControls();
        // CreateControls() does its own resizing.
        //----------------------------------------------------------------------
		resize(320, 240);

		// TODO: Place additional initialization code here
	}

	// Place additional applet clean up code here.  destroy() is called when
	// when you applet is terminating and being unloaded.
	//-------------------------------------------------------------------------
	public void destroy()
	{
		// TODO: Place applet cleanup code here
	}

	// Test Paint Handler
	//--------------------------------------------------------------------------
	public void paint(Graphics g)
	{
	  // put up an announcement of what we are doing

		g.drawString("Painting things onto image", 10, 20);

		for (int i = 0; i < NumberOfThings; i++)
		  { // for each of the things stored in our array,
                    // get their position, and draw them on the screen
                  Thing t = thingArray[i];
		  double dX = t.XPos();
		  double dY = t.YPos();

		  g.setColor( Color.red);

	
		  g.fillOval( (int) dX + xDispOff, (int) dY + yDispOff, 3, 3);
		  
		}

	}

	//		The start() method is called when the page containing the applet
	// first appears on the screen. The AppletWizard's initial implementation
	// of this method starts execution of the applet's thread.
	//--------------------------------------------------------------------------
	public void start()
	{
		// need to cycle over objects, setting up at random

		for (int i = 0; i < NumberOfThings; i++)
		{ thingArray[i] = new Thing(startValue(0, 100), startValue(0, 100));
		}

	}
			
	//		The stop() method is called when the page containing the applet is
	// no longer on the screen. The AppletWizard's initial implementation of
	// this method stops execution of the applet's thread.
	//--------------------------------------------------------------------------
	public void stop()
	{
	}

	public double startValue(int low, int high)
	{ double test = (low + ((high - low) *  Math.random()));
	return test;
	}
}

