Class Rectangle

java.lang.Object
  extended by Rectangle
All Implemented Interfaces:
Shape

public class Rectangle
extends Object
implements Shape


Constructor Summary
Rectangle(double x, double y, double width, double height)
          Constructs a rectangle.
 
Method Summary
 void draw()
          Draws this rectangle.
 void fill()
          Fills this rectangle.
 int getHeight()
          Gets the height of this rectangle.
 int getWidth()
          Gets the width of this rectangle.
 int getX()
          Gets the leftmost x-position of this rectangle.
 int getY()
          Gets the topmost y-position of this rectangle.
 void grow(double dw, double dh)
          Resizes this rectangle both horizontally and vertically.
 void paintShape(Graphics2D g2)
          Paints the shape
 void setColor(Color newColor)
          Sets the color of this rectangle.
 String toString()
           
 void translate(double dx, double dy)
          Moves this rectangle by a given amount.
 
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle(double x,
                 double y,
                 double width,
                 double height)
Constructs a rectangle.

Parameters:
x - the leftmost x-coordinate
y - the topmost y-coordinate
width - the width
height - the height
Method Detail

draw

public void draw()
Draws this rectangle.


fill

public void fill()
Fills this rectangle.


getHeight

public int getHeight()
Gets the height of this rectangle.

Specified by:
getHeight in interface Shape
Returns:
the height

getWidth

public int getWidth()
Gets the width of this rectangle.

Specified by:
getWidth in interface Shape
Returns:
the width

getX

public int getX()
Gets the leftmost x-position of this rectangle.

Specified by:
getX in interface Shape
Returns:
the leftmost x-position

getY

public int getY()
Gets the topmost y-position of this rectangle.

Specified by:
getY in interface Shape
Returns:
the topmost y-position

grow

public void grow(double dw,
                 double dh)
Resizes this rectangle both horizontally and vertically.

Parameters:
dw - the amount by which to resize the width on each side
dw - the amount by which to resize the height on each side

paintShape

public void paintShape(Graphics2D g2)
Description copied from interface: Shape
Paints the shape

Specified by:
paintShape in interface Shape
Parameters:
g2 - the graphics object

setColor

public void setColor(Color newColor)
Sets the color of this rectangle.

Parameters:
newColor - the new color

toString

public String toString()
Overrides:
toString in class Object

translate

public void translate(double dx,
                      double dy)
Moves this rectangle by a given amount.

Parameters:
dx - the amount by which to move in x-direction
dy - the amount by which to move in y-direction