/**
 * @(#)CoolProgram.java
 *
 * Sample Applet application
 *
 * @author 
 * @version 1.00 05/10/02
 */

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JApplet;
import java.util.Random;


public class CoolProgram extends JApplet implements MouseListener
{
	private Point p1;
	private Point p2;
	private Point p3;
	private Point p4;
	
	private int pointCount;
	
	private Random r;
	
	public void init() 
	{
		setBackground(Color.black);
		p1 = new Point();
		p2 = new Point();
		p3 = new Point();
		p4 = new Point();
		r = new Random();
		pointCount = 0;
		this.addMouseListener(this);
	}
	
	// Description: This method is called any time the mouse is clicked
	//		On the first click, it stores the location in variable p1
	//		On the second click, it stores the location in variable p2
	//		On the third click, it stores the location in variable p3
	//		On the fourth click, it stores the location in variable p4
	//		Then repaint.
	public void mouseClicked(MouseEvent evt)
	{
		if(pointCount == 0)
		{
			p1 = evt.getPoint();
			pointCount++;
		}
		else if (pointCount == 1)
		{
			p2 = evt.getPoint();
			pointCount++;
		}
		else if (pointCount == 2)
		{
			p3 = evt.getPoint();
			pointCount++;
		}
		else if (pointCount == 3)
		{
			p4 = evt.getPoint();
			pointCount++;
		}
			
		repaint();
	}
	
	public void mouseEntered(MouseEvent evt) { /* no action */ }
	public void mouseExited(MouseEvent evt) { /* no action */ }
	public void mousePressed(MouseEvent evt) { /* no action */ }
	public void mouseReleased(MouseEvent evt) { /* no action */ }

	public void paint(Graphics g) 
	{
		g.setColor(Color.green);
		if(pointCount == 1)
		{
			g.drawLine(p1.x, p1.y, p1.x, p1.y);	// Draw point at location p1
		}
		else if(pointCount == 2)
		{
			g.drawLine(p2.x, p2.y, p2.x, p2.y);	// Draw point at location p2
			
			g.drawLine(p1.x, p1.y, p2.x, p2.y);	// Draw line from point p1 to point p2
		}
		else if(pointCount == 3)
		{
			g.drawLine(p3.x, p3.y, p3.x, p3.y);	// Draw point at location p3
			g.drawLine(p2.x, p2.y, p3.x, p3.y);	// Draw line from point p2 to p3
			g.drawLine(p1.x, p1.y, p3.x, p3.y);	// Draw line from point p1 to p3
		}
		else
		{
			// *** TO DO ***  Please see the description on the Unit 4 assignment			
		}
			
		
	}
}
