Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
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.
public int heightThe height of the rectangle.
public int widthThe width of the rectangle.
public int xThe x coordinate of the top left corner of the rectangle.
public int yThe y coordinate of the top left corner of the rectangle.
public Rectangle()Constructs a new rectangle whose top-left corner is (0,0), and whose width and height are 0.
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
Parameter Description d the width and height
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.
Parameter Description width the width of the rectangle height the height of the 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.
Parameter Description x the x coordinate y the y coordinate width the width of the rectangle height the height of the 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.
Parameter Description p the top-left corner of the 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.
Parameter Description p the top left corner of the rectangle d the width and height
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.
Parameter Description newx the x coordinate of the new point newy the y coordinate of the new point
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.
Parameter Description pt a point
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.
Parameter Description r a rectangle
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.
Parameter Description obj the object to compare with Overrides:
equals in class Object .
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
Parameter Description h the horizontal expansion v the vertical expansion
public int hashCode()Return Value:
Returns a hash code value for this object.
Overrides:
hashCode in class Object .
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.
Parameter Description x the x coordinate y the y coordinate
public Rectangle intersection(Rectangle r)Return Value:
Returns the largest rectangle contained in both the rectangle argument and in this rectangle.
Parameter Description r a rectangle
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.
Parameter Description r a rectangle
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.
public void move(int x, int y)Moves this rectangle so that its new top-left corner is the specified (x,y) coordinate.
Parameter Description x the new x coordinate y the new y coordinate
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.
Parameter Description x the new x coordinate y the new y coordinate width the new width height the new height
public void resize(int width, int height)Resizes this rectangle so that its new width and height are the indicated arguments.
Parameter Description width the new width height the new height
public String toString()Return Value:
Returns a string representation of this rectangle.
Overrides:
toString in class Object .
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).
Parameter Description dx the amount to move the rectangle to the right dy the amount to move the rectangle downward
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.
Parameter Description r a rectangle