
import java.awt.*;
import java.util.*;


public class ColoredRectangle extends Panel {

	Color rectangleColor;

	int rectangleRed;
	int rectangleGreen;
	int rectangleBlue;

	int xPosition;
	int yPosition;

	Rectangle coloredRectangle;
	int[] xPoints = new int[5];
	int[] yPoints = new int[5];

	int rectWidth;
	int rectHeight;

	boolean selected;

	Graphics g;
	
	ColoredRectangle(int x, int y, int w, int h, Color c, Graphics g, boolean select) {

		rectangleColor = c;
		rectangleRed = rectangleColor.getRed();
		rectangleGreen = rectangleColor.getGreen();
		rectangleBlue = rectangleColor.getBlue();

		xPosition = x;
		yPosition = y;

//		xPoints = {x,x+w,x+w,x,x};
//		yPoints = {y,y,y+h.y+h,y};
		
		coloredRectangle = new Rectangle(x,y,w,h);
		rectWidth = w;
		rectHeight = h;

		selected = select;
		
		this.g = g;

		paintRectangle();
	}

	public void paintRectangle() {

		g.setColor(rectangleColor);
		g.fillRect(xPosition+2,yPosition+2,rectWidth-4,rectHeight-4);

		if (selected) {
			g.setColor(Color.white);
			g.fillRect(xPosition,yPosition,2,2);
			g.fillRect(xPosition+rectWidth-2,yPosition,2,2);
			g.fillRect(xPosition+rectWidth-2,yPosition+rectHeight-2,2,2);
			g.fillRect(xPosition,yPosition+rectHeight-2,2,2);
		}
		else {
			g.setColor(Color.black);
			g.fillRect(xPosition,yPosition,2,2);
			g.fillRect(xPosition+rectWidth-2,yPosition,2,2);
			g.fillRect(xPosition+rectWidth-2,yPosition+rectHeight-2,2,2);
			g.fillRect(xPosition,yPosition+rectHeight-2,2,2);
		}
	}

	public boolean mouseDown(Event e, int x, int y) {
		selected = true;
		paintRectangle();	
		return true;
	}	


}