java.awt
Class Rectangle

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.Rectangle
All Implemented Interfaces:
Shape, Cloneable

public class Rectangle
extends Rectangle2D
implements Shape

A rectangle with integer coordinates.

Author:
Lawrie Griffiths

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 int height
          The height of the rectangle
 int width
          The width of the rectangle
 int x
          The x coordinate of the top left of the rectangle
 int y
          The y coordinate of the top right of the rectangle
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
Rectangle()
          Creates an empty rectangle at (0,0).
Rectangle(int width, int height)
          Creates a rectangle with top left corner at (0,0) and with specified width and height.
Rectangle(int x, int y, int width, int height)
          Creates a rectangle with top left corner at (x,y) and with specified width and height.
Rectangle(Point p)
          Create an empty rectangle at the given point
 
Method Summary
 boolean contains(int x, int y)
          Test if a point given by (x,y) coordinates is within the rectangle
 boolean contains(Point p)
          Test if a point is within the rectangle
 boolean contains(Rectangle r)
          Test if this rectangle contains a specified rectangle
 boolean equals(Object obj)
          Test if the Rectangle is equal to a given object
 Rectangle getBounds()
          Get the bounds of this rectangular shape as a Rectangle
 Rectangle2D getBounds2D()
          Get the bounding Rectangle2D for the shape
 double getHeight()
          Get the height as a double
 Point getLocation()
          Get the location of the rectangle
 double getWidth()
          Get the width as a double
 double getX()
          Get the x coordinate as a double
 double getY()
          Get the y coordinate as a double
 boolean inside(int x, int y)
          Deprecated. 
 boolean intersects(Rectangle r)
          Test if this rectangle intersects a specified rectangle
 boolean isEmpty()
          Test if the rectangle is empty
 int outcode(double x, double y)
          Returns a mask value that specifies where a point lies with respect to this rectangle.
 void reshape(int x, int y, int width, int height)
          Deprecated. 
 void resize(int width, int height)
          Deprecated. 
 void setBounds(int x, int y, int width, int height)
          Set the bounds of this rectangle
 void setBounds(Rectangle r)
          Set the bounds of this rectangle to the given rectangle
 void setLocation(int x, int y)
          Move the rectangle to (x,y)
 void setLocation(Point p)
          Set the location of this point to the location of a given point
 void setRect(double x, double y, double width, double height)
          Set this rectangle to a rectangle defined by double coordinates
 void setSize(int width, int height)
          Set the size of the rectangle
 String toString()
          Returns a String representing this rectangle.
 
Methods inherited from class java.awt.geom.Rectangle2D
contains, contains, intersects, intersectsLine, outcode, setFrame, setRect
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, intersects, intersects
 

Field Detail

height

public int height
The height of the rectangle


width

public int width
The width of the rectangle


x

public int x
The x coordinate of the top left of the rectangle


y

public int y
The y coordinate of the top right of the rectangle

Constructor Detail

Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Creates a rectangle with top left corner at (x,y) and with specified width and height.

Parameters:
x - the x coordinate of the top left corner
y - the y coordinate of the top left corner
width - the width of the rectangle
height - the height of the rectangle

Rectangle

public Rectangle(int width,
                 int height)
Creates a rectangle with top left corner at (0,0) and with specified width and height.

Parameters:
width - the width of the rectangle
height - the height of the rectangle

Rectangle

public Rectangle()
Creates an empty rectangle at (0,0).


Rectangle

public Rectangle(Point p)
Create an empty rectangle at the given point

Parameters:
p - trhe point
Method Detail

getX

public double getX()
Get the x coordinate as a double

Specified by:
getX in class RectangularShape
Returns:
the x coordinate

getY

public double getY()
Get the y coordinate as a double

Specified by:
getY in class RectangularShape
Returns:
the y coordinate

getWidth

public double getWidth()
Get the width as a double

Specified by:
getWidth in class RectangularShape
Returns:
the width

getHeight

public double getHeight()
Get the height as a double

Specified by:
getHeight in class RectangularShape
Returns:
the height

setLocation

public void setLocation(int x,
                        int y)
Move the rectangle to (x,y)

Parameters:
x - the new x coordinate
y - the new y coordinate

setLocation

public void setLocation(Point p)
Set the location of this point to the location of a given point

Parameters:
p - the given point

isEmpty

public boolean isEmpty()
Test if the rectangle is empty

Specified by:
isEmpty in class RectangularShape
Returns:
true iff the rectangle is empty

contains

public boolean contains(int x,
                        int y)
Test if a point given by (x,y) coordinates is within the rectangle

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
true iff the point is within the rectangle

contains

public boolean contains(Point p)
Test if a point is within the rectangle

Parameters:
p - the point
Returns:
true iff the point is within the rectangle

contains

public boolean contains(Rectangle r)
Test if this rectangle contains a specified rectangle

Parameters:
r - the specified rectangle
Returns:
true iff the specified rectangle is contained within this rectangle

intersects

public boolean intersects(Rectangle r)
Test if this rectangle intersects a specified rectangle

Parameters:
r - the given rectangle
Returns:
true iff this rectangle intersects the given rectangle

getBounds

public Rectangle getBounds()
Description copied from class: RectangularShape
Get the bounds of this rectangular shape as a Rectangle

Specified by:
getBounds in interface Shape
Overrides:
getBounds in class RectangularShape
Returns:
the bounds as a Rectangle

getBounds2D

public Rectangle2D getBounds2D()
Description copied from interface: Shape
Get the bounding Rectangle2D for the shape

Specified by:
getBounds2D in interface Shape
Returns:
the bounding Rectangle2D

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Set the bounds of this rectangle

Parameters:
x - the new x coordinate
y - the new y coordinate
width - the new width
height - the new height

setBounds

public void setBounds(Rectangle r)
Set the bounds of this rectangle to the given rectangle

Parameters:
r - the new rectangle

setRect

public void setRect(double x,
                    double y,
                    double width,
                    double height)
Description copied from class: Rectangle2D
Set this rectangle to a rectangle defined by double coordinates

Specified by:
setRect in class Rectangle2D
Parameters:
x - the x coordinate of the top left corner
y - the y coordinate of the top right corner
width - the width of the rectangle
height - the height of the rectangle

reshape

@Deprecated
public void reshape(int x,
                               int y,
                               int width,
                               int height)
Deprecated. 

Use setBounds.


equals

public boolean equals(Object obj)
Test if the Rectangle is equal to a given object

Overrides:
equals in class Rectangle2D
Parameters:
obj - the object

getLocation

public Point getLocation()
Get the location of the rectangle

Returns:
the (x,y) coordinate of the top left corner

setSize

public void setSize(int width,
                    int height)
Set the size of the rectangle

Parameters:
width - the new width
height - the new height

resize

@Deprecated
public void resize(int width,
                              int height)
Deprecated. 

Use setSize


toString

public String toString()
Returns a String representing this rectangle.

Overrides:
toString in class Object

outcode

public int outcode(double x,
                   double y)
Description copied from class: Rectangle2D
Returns a mask value that specifies where a point lies with respect to this rectangle.

Specified by:
outcode in class Rectangle2D
Parameters:
x - the x coordinate of the given point
y - the y coordinate of the given point
Returns:
the mask value

inside

@Deprecated
public boolean inside(int x,
                                 int y)
Deprecated.