package shapes; // Shape5JA.java (for lecture demo) // cmc, 11/23/00 import java.awt.Graphics; /** Abstract base class of various drawable shapes. */ public abstract class Shape5JA { private int x, y; // location on Graphics object private int width, height; // size of shape in pixels /** Draw method to be implemented by subclasses. @param g the Graphics object to draw on, presumably passed along from a paint method. */ public abstract void draw(Graphics g); // Note: all other methods are implemented in this class /** Default constructor sets all dimensions to 0. */ public Shape5JA() { setX(0); setY(0); setWidth(0); setHeight(0); } /** Better constructor sets dimensions as requested. @param x X coordinate @param y Y coordinate @param w Width @param h Height */ public Shape5JA(int x, int y, int w, int h) { setX(x); setY(y); setWidth(w); setHeight(h); } /** Sets X coordinate to value of the parameter. */ public void setX(int value) { x = value; } /** Sets Y coordinate to value of the parameter. */ public void setY(int value) { y = value; } /** Sets width to value of the parameter. */ public void setWidth(int value) { width = value; } /** Sets height to value of the parameter. */ public void setHeight(int value) { height = value; } /** Returns X coordinate. */ public int x() { return x; } /** Returns Y coordinate. */ public int y() { return y; } /** Returns width. */ public int width() { return width; } /** Returns height. */ public int height() { return height; } }