m865.shapepack
Class Shape

java.lang.Object
  extended bym865.shapepack.Shape
Direct Known Subclasses:
Ellipse, Rectangle

public abstract class Shape
extends java.lang.Object

The Shape class is an abstract class which defines the fields, methods and behavior common to all shapes.

Version:
1.0 09/01/05
Author:
Daniel D. Warner

Field Summary
protected  java.awt.Color color
          Fill color for the shape
static java.awt.Color defaultColor
          Constant specifying the default fill color for a shape.
static int defaultHeight
          Constant specifying the default height of a shape.
static int defaultWidth
          Constant specifying the default width of a shape.
protected  int height
          Height of the bounding box.
protected  int width
          Width of the bounding box.
protected  int x
          Horizontal coordinate of the upper left corner of the bounding box.
protected  int y
          Vertical coordinate of the upper left corner of the bounding box.
 
Constructor Summary
Shape(int x, int y, int w, int h, java.awt.Color c)
          The generic constructor for shape objects.
 
Method Summary
abstract  float area()
          Calculates the area of the shape.
abstract  void draw(java.awt.Graphics g)
          Draws the shape.
 java.awt.Color getColor()
           
 int getHeight()
           
 int getWidth()
           
 int getX()
           
 int getY()
           
 void moveTo(int x, int y)
          Moves the shape by setting the upper left corner of the bounding box to the specified coordinates.
abstract  float perimeter()
          Calculates the perimeter of the shape.
 void setColor(java.awt.Color color)
           
 void setHeight(int h)
           
 void setWidth(int w)
           
 java.lang.String toString()
          Generates a string describing the parameters of the shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultWidth

public static final int defaultWidth
Constant specifying the default width of a shape.

See Also:
Constant Field Values

defaultHeight

public static final int defaultHeight
Constant specifying the default height of a shape.

See Also:
Constant Field Values

defaultColor

public static final java.awt.Color defaultColor
Constant specifying the default fill color for a shape.


x

protected int x
Horizontal coordinate of the upper left corner of the bounding box.


y

protected int y
Vertical coordinate of the upper left corner of the bounding box.


width

protected int width
Width of the bounding box.


height

protected int height
Height of the bounding box.


color

protected java.awt.Color color
Fill color for the shape

Constructor Detail

Shape

public Shape(int x,
             int y,
             int w,
             int h,
             java.awt.Color c)
The generic constructor for shape objects.

Parameters:
x - horizontal coordinate of the upper left corner of the bounding box.
y - vertical coordinate of the upper left corner of the bounding box.
w - width of the bounding box.
h - height of the bounding box.
c - fill color for the shape.
Method Detail

moveTo

public void moveTo(int x,
                   int y)
Moves the shape by setting the upper left corner of the bounding box to the specified coordinates.

Parameters:
x - the new horizontal coordinate of the upper left corner of the bounding box.
y - the new vertical coordinate of the upper left corner of the bounding box.

getX

public int getX()
Returns:
the horizontal coordinate of the upper left corner of the bounding box.

getY

public int getY()
Returns:
the vertical coordinate of the upper left corner of the bounding box.

getWidth

public int getWidth()
Returns:
the width of the bounding box.

setWidth

public void setWidth(int w)
Parameters:
w - the new width of the bounding box.

getHeight

public int getHeight()
Returns:
the height of the bounding box.

setHeight

public void setHeight(int h)
Parameters:
h - the new height of the bounding box.

getColor

public java.awt.Color getColor()
Returns:
the fill color of the shape.

setColor

public void setColor(java.awt.Color color)
Parameters:
color - the new fill color for the shape.

draw

public abstract void draw(java.awt.Graphics g)
Draws the shape.

Parameters:
g - the graphics object on which the shape is to be drawn.

area

public abstract float area()
Calculates the area of the shape.

Returns:
the area

perimeter

public abstract float perimeter()
Calculates the perimeter of the shape.

Returns:
the perimeter

toString

public java.lang.String toString()
Generates a string describing the parameters of the shape.