import java.awt.Color; public class Rectangle implements Drawable { private Point startPoint; private Point endPoint; private int lineWidth; private Color color; public Rectangle(Point startPoint, Point endPoint, int lineWidth, Color color) { this.startPoint = startPoint; this.endPoint = endPoint; this.lineWidth = lineWidth; this.color = color; } public Rectangle(Point startPoint, int width, int height, int lineWidth, Color color) { this(startPoint, new Point(width + startPoint.getX(), height + startPoint.getY()), lineWidth, color); } public Rectangle(int x, int y, int width, int height, int lineWidth, Color color) { this(new Point(x, y), width, height, lineWidth, color); } public Rectangle(int x, int y, int width, int height, int lineWidth) { this(x, y, width, height, lineWidth, Color.BLACK); } public Rectangle(int x, int y, int width, int height) { this(x, y, width, height, 1); } public void draw(SimpleWindow w) { Color oldColor = w.getLineColor(); int oldLineWidth = w.getLineWidth(); w.setLineWidth(lineWidth); w.setLineColor(color); startPoint.drawAngle(endPoint, w); endPoint.drawAngle(startPoint, w); w.setLineColor(oldColor); w.setLineWidth(oldLineWidth); } public int getX2() { return endPoint.getX(); } public int getY2() { return endPoint.getY(); } public Point getEndPoint() { return endPoint; } }