java.awt
Class Rectangle

java.lang.Object
  |
  +--java.awt.Rectangle

public class Rectangle
extends Object

A rectangle defined by x, y, width and height.


Field Summary
 int height
          The height of the rectangle.
 int width
          The width of the rectangle.
 int x
          The x coordinate of the rectangle.
 int y
          The y coordinate of the rectangle.
 
Constructor Summary
Rectangle()
          Constructs a new rectangle.
Rectangle(Dimension d)
          Constructs a rectangle and initializes it to the specified width and height.
Rectangle(int width, int height)
          Constructs a rectangle and initializes it with the specified width and height parameters.
Rectangle(int x, int y, int width, int height)
          Constructs and initializes a rectangle with the specified parameters.
Rectangle(Point p)
          Constructs a rectangle and initializes it to the specified point.
Rectangle(Point p, Dimension d)
          Constructs a rectangle and initializes it to a specified point and dimension.
 
Method Summary
 void add(int newx, int newy)
          Adds a point to a rectangle.
 void add(Point pt)
          Adds a point to a rectangle.
 void add(Rectangle r)
          Adds a rectangle to a rectangle.
 boolean equals(Object obj)
          Checks whether two rectangles are equal.
 void grow(int h, int v)
          Grows the rectangle horizontally and vertically.
 int hashCode()
          Returns the hashcode for this Rectangle.
 boolean inside(int x, int y)
          Checks if the specified point lies inside a rectangle.
 Rectangle intersection(Rectangle r)
          Computes the intersection of two rectangles.
 boolean intersects(Rectangle r)
          Checks if two rectangles intersect.
 boolean isEmpty()
          Determines whether the rectangle is empty.
 void move(int x, int y)
          Moves the rectangle.
 void reshape(int x, int y, int width, int height)
          Reshapes the rectangle.
 void resize(int width, int height)
          Resizes the rectangle.
 String toString()
          Returns the String representation of this Rectangle's values.
 void translate(int x, int y)
          Translates the rectangle.
 Rectangle union(Rectangle r)
          Computes the union of two rectangles.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x
The x coordinate of the rectangle.


y

public int y
The y coordinate of the rectangle.


width

public int width
The width of the rectangle.


height

public int height
The height of the rectangle.

Constructor Detail

Rectangle

public Rectangle()
Constructs a new rectangle.


Rectangle

public Rectangle(int x,
                 int y,
                 int width,
                 int height)
Constructs and initializes a rectangle with the specified parameters.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the rectangle
height - the height of the rectangle

Rectangle

public Rectangle(int width,
                 int height)
Constructs a rectangle and initializes it with the specified width and height parameters.

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

Rectangle

public Rectangle(Point p,
                 Dimension d)
Constructs a rectangle and initializes it to a specified point and dimension.

Parameters:
p - the point
d - dimension

Rectangle

public Rectangle(Point p)
Constructs a rectangle and initializes it to the specified point.

Parameters:
p - the value of the x and y coordinate

Rectangle

public Rectangle(Dimension d)
Constructs a rectangle and initializes it to the specified width and height.

Parameters:
d - the value of the width and height
Method Detail

reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
Reshapes the rectangle.


move

public void move(int x,
                 int y)
Moves the rectangle.


translate

public void translate(int x,
                      int y)
Translates the rectangle.


resize

public void resize(int width,
                   int height)
Resizes the rectangle.


inside

public boolean inside(int x,
                      int y)
Checks if the specified point lies inside a rectangle.

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

intersects

public boolean intersects(Rectangle r)
Checks if two rectangles intersect.


intersection

public Rectangle intersection(Rectangle r)
Computes the intersection of two rectangles.


union

public Rectangle union(Rectangle r)
Computes the union of two rectangles.


add

public void add(int newx,
                int newy)
Adds a point to a rectangle. This results in the smallest rectangle that contains both the rectangle and the point.


add

public void add(Point pt)
Adds a point to a rectangle. This results in the smallest rectangle that contains both the rectangle and the point.


add

public void add(Rectangle r)
Adds a rectangle to a rectangle. This results in the union of the two rectangles.


grow

public void grow(int h,
                 int v)
Grows the rectangle horizontally and vertically.


isEmpty

public boolean isEmpty()
Determines whether the rectangle is empty.


hashCode

public int hashCode()
Returns the hashcode for this Rectangle.

Overrides:
hashCode in class Object
See Also:
Hashtable

equals

public boolean equals(Object obj)
Checks whether two rectangles are equal.

Overrides:
equals in class Object
Parameters:
obj - the Object to compare with
Returns:
true if these Objects are equal; false otherwise.
See Also:
Hashtable

toString

public String toString()
Returns the String representation of this Rectangle's values.

Overrides:
toString in class Object