// Rect.java // Class for a rectangle. // Written by THC for CS 5 HW 3. Modified by Scot Drysdale. import java.awt.Color; import java.awt.Graphics; public class Rect implements Drawable { private int left, top; // left and top of Rect private int width, height; // Rect's height and width private Color color; // Rect's color // Constructor just saves the parameters in the instance variables. public Rect(int left, int top, int width, int height, Color color) { this.color = color; this.left = left; this.top = top; this.width = width; this.height = height; } // Have the Rect draw itself. public void draw(Graphics page) { page.setColor(color); page.drawRect(left, top, width, height); } // Return true if the Rect contains Point p, false otherwise. public boolean containsPoint(PointShape p) { return p.getX() >= left && p.getX() <= left + width && p.getY() >= top && p.getY() <= top + height; } }