// Rect.java // Class for a rectangle. // Written by THC for CS 5 Lab Assignment 3. import java.awt.*; public class Rect extends Shape { private int left, top; // left and top of Rect private int width, height; // Rect's height and width // Constructor just saves the parameters in the instance variables. public Rect(int left, int top, int width, int height, Color color) { super(color); this.left = left; this.top = top; this.width = width; this.height = height; } // Have the Rect draw itself. public void drawShape(Graphics page) { page.fillRect(left, top, width, height); } // Return true if the Rect contains Point p, false otherwise. public boolean containsPoint(Point p) { return p.x >= left && p.x <= left + width && p.y >= top && p.y <= top + height; } // Have the Rect move itself. public void move(int deltaX, int deltaY) { left += deltaX; top += deltaY; } // Return the Rect's center. public Point getCenter() { return new Point(left + (width / 2), top + (height / 2)); } }