m865.shapepack
Class Rectangle

java.lang.Object
  extended by m865.shapepack.Shape
      extended by m865.shapepack.Rectangle
Direct Known Subclasses:
Square

public class Rectangle
extends Shape

The concrete Shape subclass that defines rectangles.


Field Summary
 
Fields inherited from class m865.shapepack.Shape
color, defaultColor, defaultHeight, defaultWidth, height, width, x, y
 
Constructor Summary
Rectangle(int x, int y)
          Constructor for a rectangle at the specified location with the default width, height, and color.
Rectangle(int x, int y, int w, int h, java.awt.Color c)
          The generic Rectangle constructor
 
Method Summary
 float area()
          Calculates the area.
 void draw(java.awt.Graphics g)
          Draws the rectangle
 float perimeter()
          Calculates the perimeter.
 java.lang.String toString()
          Generates the string describing the rectangle.
 
Methods inherited from class m865.shapepack.Shape
getColor, getHeight, getWidth, getX, getY, moveTo, setColor, setHeight, setWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle(int x,
                 int y,
                 int w,
                 int h,
                 java.awt.Color c)
The generic Rectangle constructor

Parameters:
x - horizontal coordinate of the upper left corner of the rectangle.
y - vertical coordinate of the upper left corner of the rectangle.
w - width of the rectangle.
h - height of the rectangle.
c - fill color for the rectangle.

Rectangle

public Rectangle(int x,
                 int y)
Constructor for a rectangle at the specified location with the default width, height, and color.

Parameters:
x - horizontal coordinate of the upper left corner of the rectangle.
y - vertical coordinate of the upper left corner of the rectangle.
Method Detail

draw

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

Specified by:
draw in class Shape
Parameters:
g - the graphics object on which the shape is to be drawn.

area

public float area()
Calculates the area.

Specified by:
area in class Shape
Returns:
the area of the rectangle

perimeter

public float perimeter()
Calculates the perimeter.

Specified by:
perimeter in class Shape
Returns:
the perimeter of the rectangle

toString

public java.lang.String toString()
Generates the string describing the rectangle.

Overrides:
toString in class Shape