package proj4; import java.awt.Color; import java.awt.Graphics; public class ColoredRectangle extends ColoredShape { private int width; private int height; public ColoredRectangle(int x, int y, Color c, int width, int height) { super(x, y, c); this.width = width; this.height = height; } public int getWidth() { return width; } public int getHeight() { return height; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public String toString() { return "Rectangle "+width + " by "+ height + " " + super.toString(); } public void draw(Graphics g) { g.setColor(getColor()); if (isFilled()) g.fillRect(getX(), getY(), width, height); else g.drawRect(getX(),getY(),width,height); } public boolean inside(int x, int y) { if (x < getX()) return false; if (x > getX() + width) return false; if (y < getY()) return false; if (y > getY() + height) return false; return true; } }