//PlotRandom.java -- plots a random distribution to a 300x300 square
//clicking the screen clears it. 

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

public class PlotRandom extends java.applet.Applet implements Runnable
{
	public static final int SQUARE_SIZE = 600; //size of square to plot in
	Graphics g = null;
	Thread t = null;

	RandFunctionWrapper rfw = new RandFunctionWrapper (0, PlotRandom.SQUARE_SIZE, 1);
	RandFunctionWrapper rfw2 = new RandFunctionWrapper (0, 255, 1);

	public void init()
	{
		g= getGraphics();
	}


	public void start()
	{
		if (t == null)
		{
		t = new Thread(this);	
		t.start();
		}
	}
	
	public void stop()
	{
		if (t != null)
			{
			t.stop();	
			t = null;
			}

	}

	public void run()
	{
		while(t != null)
		{
		int x = rfw.getInt();
		int y = rfw.getInt();
		//new thing -- set the color to a random value
		g.setColor(new Color(rfw2.getInt(), rfw2.getInt(),rfw2.getInt() ));
		g.drawLine(x, y, x+1, y+1 ); //draw a point by drawing a line  
		//System.out.print(".");
		}
		
	}

	public boolean handleEvent(Event e)
	{
		switch(e.id)
		{
			case (Event.MOUSE_DOWN):
				System.out.println("bang!");			
				repaint();
				break;
		}

		return super.handleEvent(e);
	}



}