m865.shapepack
Class ShapeFactory

java.lang.Object
  extended by m865.shapepack.ShapeFactory

public class ShapeFactory
extends java.lang.Object

The ShapeFactory class is a factory class which provides a catalog of the shapes it can make and two creation methods which will construct any shape in the catalog.


Field Summary
protected static java.lang.String ELLIPSE
           
protected static java.lang.String RECTANGLE
           
protected static java.lang.String SQUARE
           
protected  java.lang.String[] theList
          The list containing the names of the shapes that this factory knows how to make.
 
Constructor Summary
ShapeFactory()
           
 
Method Summary
 Shape createShape(java.lang.String shapeName, int x, int y)
          Creates a specified shape with a default color and a bounding box of the default size.
 Shape createShape(java.lang.String shapeName, int x, int y, int w, int h, java.awt.Color c)
          Creates a specified shape
 java.lang.String[] getTheList()
           
static void main(java.lang.String[] args)
          Provides a unit test.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RECTANGLE

protected static final java.lang.String RECTANGLE
See Also:
Constant Field Values

ELLIPSE

protected static final java.lang.String ELLIPSE
See Also:
Constant Field Values

SQUARE

protected static final java.lang.String SQUARE
See Also:
Constant Field Values

theList

protected java.lang.String[] theList
The list containing the names of the shapes that this factory knows how to make.

Constructor Detail

ShapeFactory

public ShapeFactory()
Method Detail

getTheList

public java.lang.String[] getTheList()
Returns:
the names of the known shapes.

createShape

public Shape createShape(java.lang.String shapeName,
                         int x,
                         int y,
                         int w,
                         int h,
                         java.awt.Color c)
Creates a specified shape

Parameters:
shapeName - the name of the shape.
x - the horizontal coordinate of the upper left corner of the bounding box.
y - the vertical coordinate of the upper left corner of the bounding box.
w - the width of the bounding box.
h - the height of the bounding box.
c - the fill color of the shape.
Returns:
an instantiation of the specified shape. If the name is not a shape in the list, then this method returns a square.

createShape

public Shape createShape(java.lang.String shapeName,
                         int x,
                         int y)
Creates a specified shape with a default color and a bounding box of the default size.

Parameters:
shapeName - the name of the shape.
x - the horizontal coordinate of the upper left corner of the bounding box.
y - the vertical coordinate of the upper left corner of the bounding box.
Returns:
an instantiation of the specified shape. If the name is not a shape in the list, then this method returns a square.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string containing the class name and the list of shapes

main

public static void main(java.lang.String[] args)
Provides a unit test.
  1. Creates an instance of ShapeFactory and prints out the toString info.
  2. Creates a shape corresponding to each input argument and prints out that shape's toString info.