uwcse.graphics
Class Rectangle

java.lang.Object
  |
  +--uwcse.graphics.ShapeImpl
        |
        +--uwcse.graphics.Rectangle
All Implemented Interfaces:
Shape

public class Rectangle
extends ShapeImpl
implements Shape

A rectangle shape. The main operations are to read the x and y coordinates of the upper-left corner of the rectangle (getX() and getY()), to change the position of the rectangle (moveBy(...) and moveTo(...)), to rotate the position of the rectangle around some point (rotateAround(...)), to read and change the color of the rectangle (getColor() and setColor(...)), to read and change the width and height of the rectangle (getWidth(), getHeight(), and resize(...)), and add to and remove from a GWindow (addTo(...) and removeFromWindow()). Other operations are mainly for internal use, and should not be called by regular client programs.


Constructor Summary
Rectangle()
          Create a new, filled rectangle, colored red, with a default location and size.
Rectangle(int x, int y, int width, int height)
          Create a new unfilled, black rectangle with the given position and size.
Rectangle(int x, int y, int width, int height, java.awt.Color c, boolean fill)
          Create a new rectangle of the given position, size, color, and filledness.
 
Method Summary
 int getHeight()
          Return the height of the rectangle
 int getWidth()
          Return the width of the rectangle
 int getX()
          Return the X coordinate of the rectangle's upper-left corner
 int getY()
          Return the Y coordinate of the rectangle's upper-left corner
 boolean intersects(Rectangle r)
          Return whether the argument rectangle intersects this rectangle
 void moveTo(int x, int y)
          Move the upper-left corner of the rectangle to the given coordinates.
 void paint(java.awt.Graphics g)
          Paint this shape onto the given graphics context.
 void resize(int newWidth, int newHeight)
          Change the width and height of the rectangle
 java.lang.String toString()
          Answer the printed representation of this shape.
 
Methods inherited from class uwcse.graphics.ShapeImpl
addTo, currentWindow, getBoundingBox, getCenterX, getCenterY, getColor, intersects, moveBy, recordWindow, removeFromWindow, rotateAround, setColor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface uwcse.graphics.Shape
addTo, currentWindow, getBoundingBox, getCenterX, getCenterY, getColor, intersects, moveBy, recordWindow, removeFromWindow, rotateAround, setColor
 

Constructor Detail

Rectangle

public Rectangle()
Create a new, filled rectangle, colored red, with a default location and size.

Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Create a new unfilled, black rectangle with the given position and size.
Parameters:
x - the x coordinate of the upper left corner
y - the y coordinate of the upper left corner
width - the width of the rectangle
height - the height of the rectangle

Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height,
                 java.awt.Color c,
                 boolean fill)
Create a new rectangle of the given position, size, color, and filledness.
Parameters:
x - the x coordinate of the upper left corner
y - the y coordinate of the upper left corner
width - the width of the rectangle
height - the height of the rectangle
c - the color of the rectangle
fill - should it be filled?
Method Detail

getHeight

public int getHeight()
Return the height of the rectangle
Specified by:
getHeight in interface Shape
Overrides:
getHeight in class ShapeImpl

getWidth

public int getWidth()
Return the width of the rectangle
Specified by:
getWidth in interface Shape
Overrides:
getWidth in class ShapeImpl

getX

public int getX()
Return the X coordinate of the rectangle's upper-left corner
Specified by:
getX in interface Shape
Overrides:
getX in class ShapeImpl

getY

public int getY()
Return the Y coordinate of the rectangle's upper-left corner
Specified by:
getY in interface Shape
Overrides:
getY in class ShapeImpl

intersects

public boolean intersects(Rectangle r)
Return whether the argument rectangle intersects this rectangle

moveTo

public void moveTo(int x,
                   int y)
Move the upper-left corner of the rectangle to the given coordinates.
Specified by:
moveTo in interface Shape
Overrides:
moveTo in class ShapeImpl
Parameters:
x - new X coordinate
y - new Y coordinate

paint

public void paint(java.awt.Graphics g)
Description copied from interface: Shape
Paint this shape onto the given graphics context. For internal use only.
Specified by:
paint in interface Shape

resize

public void resize(int newWidth,
                   int newHeight)
Change the width and height of the rectangle
Parameters:
newWidth - the new width
newHeight - the new height

toString

public java.lang.String toString()
Description copied from class: ShapeImpl
Answer the printed representation of this shape.
Overrides:
toString in class ShapeImpl