/** * GeomShape.java * * Declares an abstract class for a geometric shape. * @author Scot Drysdale on 4/26/00 */ import java.awt.*; public abstract class GeomShape { private Color myColor; // Shape's color /** * Constructor. * @param theColor the color of the geometric shape. */ public GeomShape(Color theColor) { myColor = theColor; } /** * @return the shape's color */ public Color getColor() { return myColor; } /** * Set the shape's color. * @param theColor the new color for the shape */ public void setColor(Color theColor) { myColor = theColor; } /** * Have the GeomShape object draw itself on the page passed as a parameter. * This leaves the Graphics object's color unchanged. * @param page the Graphics object to draw on */ public void draw(Graphics page) { Color savedColor = page.getColor(); // Save the current color. page.setColor(myColor); // Set the color. drawShape(page); // Draw the shape in the shape's color. page.setColor(savedColor); // Restore the color we had on the way in. } // Note that these method declarations are abstract declarations. // They have the modifier 'abstract' and they have semicolons instead of // method bodies. /** * Abstract method for drawing a specific type of shape. * Should be callable only within this class and its subclasses. * @param page the Graphics object to draw on */ protected abstract void drawShape(Graphics page); /** * @return the area of the shape */ public abstract double areaOf(); /** * Move the point by deltaX in x and deltaY in y. * @param deltaX the change in the x direction * @param deltaY the change in the y direction */ public abstract void move(int deltaX, int deltaY); }