/**
 * @(#)ProjectTemplate.java
 *
 * Sample Applet application
 *
 * @author 
 * @version 1.00 05/10/02
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JApplet;
import java.util.Random;


public class ProjectTemplate extends JApplet implements MouseListener
{
	private Rectangle [][] theGrid;
	private Point pointClicked;
	
	
	public void init() 
	{
		theGrid = new Rectangle [3][3];
		pointClicked = new Point(0, 0);
		
		int width = 100;
		int height = 100;
		
		Dimension rectDim = new Dimension(width, height);
		
		for(int row = 0; row < 3; row++)
		{
			for (int col = 0; col < 3; col++)
			{
				Point upperLeft = new Point(150 + width*col, 50 + height * row);
				theGrid[row][col] = new Rectangle(upperLeft, rectDim);
			}
		}
		
		setBackground(Color.white);
			
		
		this.addMouseListener(this);
	}

	// The following methods are required to implement a MouseListener	
	public void mouseClicked(MouseEvent evt)
	{
		pointClicked = evt.getPoint();
		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.blue);

		for(int row = 0; row < 3; row++)
		{
			for (int col = 0; col < 3; col++)
			{
				if(theGrid[row][col].contains(pointClicked))
				{
					g.fillRect(theGrid[row][col].x,
						   	   theGrid[row][col].y,
						       theGrid[row][col].width,
						       theGrid[row][col].height);
				}
			}
		}
		
		g.setColor(Color.black);
		
		for(int row = 0; row < 3; row++)
		{
			for (int col = 0; col < 3; col++)
			{
				g.drawRect(theGrid[row][col].x,
						   theGrid[row][col].y,
						   theGrid[row][col].width,
						   theGrid[row][col].height);
			}
		}
		
		
		
	
		
	}
}
