java.awt
Class Rectangle

java.lang.Object
  extended by java.awt.Rectangle

public class Rectangle
extends Object

Minimal Rectangle implementation.

Author:
Lawrie Griffiths

Field Summary
 int height
           
 int width
           
 int x
           
 int y
           
 
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.
 
Method Summary
 boolean contains(int pointX, int pointY)
          Test if a point given by (x,y) coordinates are with the rectangle
 boolean contains(Rectangle r)
          Test if this rectangle contains a specified rectangle
 double getHeight()
          Get the height as a double
 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 intersects(Rectangle r)
          Test if this rectangle intersects a specified rectangle
 boolean isEmpty()
          Test if the rectangle is empty
 void setLocation(int x, int y)
          Move the rectangle to (x,y)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

height

public int height

width

public int width

x

public int x

y

public int y
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).

Method Detail

getX

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

Returns:
the x coordinate

getY

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

Returns:
the y coordinate

getWidth

public double getWidth()
Get the width as a double

Returns:
the width

getHeight

public double getHeight()
Get the height as a double

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

isEmpty

public boolean isEmpty()
Test if the rectangle is empty

Returns:
true iff the rectangle is empty

contains

public boolean contains(int pointX,
                        int pointY)
Test if a point given by (x,y) coordinates are with the rectangle

Parameters:
pointX - the x coordinate
pointY - the y coordinate
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