Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Rectangle

Fields , Constructors , Methods

public  class  java.awt.Rectangle
    extends  java.lang.Object  
{
        // Fields
    public int height;	
    public int width;	
    public int x;	
    public int y;	

        // Constructors
    public Rectangle();	
    public Rectangle(Dimension  d);	
    public Rectangle(int  width, int  height);	
    public Rectangle(int  x, int  y, int  width, int height);	
    public Rectangle(Point  p);	
    public Rectangle(Point  p, Dimension  d);	

        // Methods
    public void add(int  newx, int  newy);	
    public void add(Point  pt);	
    public void add(Rectangle  r);	
    public boolean equals(Object  obj);	
    public void grow(int  h, int  v);	
    public int hashCode();	
    public boolean inside(int  x, int  y);	
    public Rectangle intersection(Rectangle  r);	
    public boolean intersects(Rectangle  r);	
    public boolean isEmpty();	
    public void move(int  x, int  y);	
    public void reshape(int  x, int  y, int  width, int height);	
    public void resize(int  width, int  height);	
    public String toString();	
    public void translate(int  dx, int  dy);	
    public Rectangle union(Rectangle  r);	
}

A rectangle specifies an area defined by its top-left (x,y) coordinate, its width and its height.


Fields


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 corner of the rectangle.


y

public int y 

The y coordinate of the top left corner of the rectangle.


Constructors


Rectangle

public Rectangle() 

Constructs a new rectangle whose top-left corner is (0,0), and whose width and height are 0.


Rectangle

public Rectangle(Dimension  d) 

Constructs a new rectangle whose top-left corner is (0,0) and whose width and height are specified by the dimension argument

ParameterDescription
d the width and height


Rectangle

public Rectangle(int  width, int  height) 

Constructs a new rectangle whose top-left corner is (0,0) and whose width and height are the specified arguments.

ParameterDescription
width the width of the rectangle
height the height of the rectangle


Rectangle

public Rectangle(int  x, int  y, int  width, int  height) 

Constructs a new rectangle whose top-left corner is (x,y) and whose width and height are the specified arguments.

ParameterDescription
x the x coordinate
y the y coordinate
width the width of the rectangle
height the height of the rectangle


Rectangle

public Rectangle(Point  p) 

Constructs a new rectangle whose top-left corner is the specified point argument and whose width and height are 0.

ParameterDescription
p the top-left corner of the rectangle


Rectangle

public Rectangle(Point  p, Dimension  d) 

Constructs a new rectangle whose top-left corner is the specified point argument and and whose width and height are specified by the dimension argument.

ParameterDescription
p the top left corner of the rectangle
d the width and height


Methods


add

public void add(int  newx, int  newy) 

Adds the point (newx, newy) to this rectangle.

This rectangle is modified to be the smallest rectangle that contains both this rectangle and the point.

ParameterDescription
newx the x coordinate of the new point
newy the y coordinate of the new point


add

public void add(Point  pt) 

Adds the point to this rectangle.

This rectangle is modified to be the smallest rectangle that contains both this rectangle and the point.

ParameterDescription
pt a point


add

public void add(Rectangle  r) 

Adds the rectangle argument to this rectangle.

This rectangle is modified to be the smallest rectangle that contains both rectangles.

ParameterDescription
r a rectangle


equals

public boolean equals(Object  obj) 

The result is true if and only if the argument is not null and is a Rectangle object that has the same top-left corner, width, and height as this object.

Return Value:

Returns true if the objects are the same; false otherwise.

ParameterDescription
obj the object to compare with

Overrides:

equals in class Object .


grow

public void grow(int  h, int  v) 

Modifies the rectangle so that it is h units larger on both the left and right size, and v units larger at both the top and bottom.

The new rectangle has (x-h, y-v) as its top-left corner, a width of x + 2h and a height of y + 2v

ParameterDescription
h the horizontal expansion
v the vertical expansion


hashCode

public int hashCode() 

Return Value:

Returns a hash code value for this object.

Overrides:

hashCode in class Object .


inside

public boolean inside(int  x, int  y) 

Checks if the specified point lies inside this rectangle.

Return Value:

Returns true if the point (x,y) is inside this rectangle; false otherwise.

ParameterDescription
x the x coordinate
y the y coordinate


intersection

public Rectangle intersection(Rectangle  r) 

Return Value:

Returns the largest rectangle contained in both the rectangle argument and in this rectangle.

ParameterDescription
r a rectangle


intersects

public boolean intersects(Rectangle  r) 

Determines if this rectangle and the rectangle argument intersect. Two rectangles insersect if their intersection is non-empty.

Return Value:

Returns true if the rectangle argument and this rectangle insersect; false otherwise.

ParameterDescription
r a rectangle


isEmpty

public boolean isEmpty() 

Determines if this rectangle is empty. A rectangle is empty if its width or its height is less than or equal to zero.

Return Value:

Returns true if this rectangle is empty; false otherwise.


move

public void move(int  x, int  y) 

Moves this rectangle so that its new top-left corner is the specified (x,y) coordinate.

ParameterDescription
x the new x coordinate
y the new y coordinate


reshape

public void reshape(int  x, int  y, int  width, int  height) 

Reshapes this rectangle so that its new top-left corner is the specified (x,y) coordinate and its new width and height are the specified arguments.

ParameterDescription
x the new x coordinate
y the new y coordinate
width the new width
height the new height


resize

public void resize(int  width, int  height) 

Resizes this rectangle so that its new width and height are the indicated arguments.

ParameterDescription
width the new width
height the new height


toString

public String toString() 

Return Value:

Returns a string representation of this rectangle.

Overrides:

toString in class Object .


translate

public void translate(int  dx, int  dy) 

Translates this rectangle by dx to the right and dy downward so that its top-left corner is now point (x+dx, y+dy), where it had been the point (x,y).

ParameterDescription
dx the amount to move the rectangle to the right
dy the amount to move the rectangle downward


union

public Rectangle union(Rectangle  r) 

Computes the union of this rectangle with the argument rectangle.

Return Value:

Returns the smallest rectangle containing both the rectangle argument and this rectangle.

ParameterDescription
r a rectangle



Top© 1996 Sun Microsystems, Inc. All rights reserved.