public class Rectangle extends ShapeImpl implements Shape
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
addTo, currentWindow, getBoundingBox, getCenterX, getCenterY, getColor, intersects, moveBy, recordWindow, removeFromWindow, rotateAround, setColor
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
addTo, currentWindow, getBoundingBox, getCenterX, getCenterY, getColor, intersects, moveBy, recordWindow, removeFromWindow, rotateAround, setColor
public Rectangle()
public Rectangle(int x, int y, int width, int height)
x
- the x coordinate of the upper left cornery
- the y coordinate of the upper left cornerwidth
- the width of the rectangleheight
- the height of the rectanglepublic Rectangle(int x, int y, int width, int height, java.awt.Color c, boolean fill)
x
- the x coordinate of the upper left cornery
- the y coordinate of the upper left cornerwidth
- the width of the rectangleheight
- the height of the rectanglec
- the color of the rectanglefill
- should it be filled?public boolean intersects(Rectangle r)
public void paint(java.awt.Graphics g)
Shape
public int getX()
public int getY()
public int getWidth()
public int getHeight()
public void resize(int newWidth, int newHeight)
newWidth
- the new widthnewHeight
- the new heightpublic void moveTo(int x, int y)