Packages This Package Prev Next Index
§1.36 Class Rectangle
public class java.awt.Rectangle
extends java.lang.Object (I-§1.12)
{
// Fields
public int height; §1.36.1
public int width; §1.36.2
public int x; §1.36.3
public int y; §1.36.4
// Constructors
public Rectangle(); §1.36.5
public Rectangle(Dimension d); §1.36.6
public Rectangle(int width, int height); §1.36.7
public Rectangle(int x, int y, int width, int height); §1.36.8
public Rectangle(Point p); §1.36.9
public Rectangle(Point p, Dimension d); §1.36.10
// Methods
public void add(int newx, int newy); §1.36.11
public void add(Point pt); §1.36.12
public void add(Rectangle r); §1.36.13
public boolean equals(Object obj); §1.36.14
public void grow(int h, int v); §1.36.15
public int hashCode(); §1.36.16
public boolean inside(int x, int y); §1.36.17
public Rectangle intersection(Rectangle r); §1.36.18
public boolean intersects(Rectangle r); §1.36.19
public boolean isEmpty(); §1.36.20
public void move(int x, int y); §1.36.21
public void reshape(int x, int y, int width, int height); §1.36.22
public void resize(int width, int height); §1.36.23
public String toString(); §1.36.24
public void translate(int dx, int dy); §1.36.25
public Rectangle union(Rectangle r); §1.36.26
}
A rectangle specifies an area defined by its top-left
coordinate, its width and its
height.
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.
Rectangle
public Rectangle()
- Constructs a new rectangle whose top-left corner is
, and whose
width and height are 0.
Rectangle
public Rectangle(Dimension d)
- Constructs a new rectangle whose top-left corner is
and whose
width and height are specified by the dimension argument
- Parameters:
d
-
the width and height
Rectangle
public Rectangle(int width, int height)
- Constructs a new rectangle whose top-left corner is
and whose
width and height are the specified arguments.
- Parameters:
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
and whose
width and height are the specified arguments.
- Parameters:
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.
- Parameters:
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.
- Parameters:
p
-
the top left corner of the rectangle
d
-
the width and height
add
public void add(int newx, int newy)
- Adds the point
to this rectangle.
- This rectangle is modified to be the smallest rectangle that contains both
this rectangle and the point.
- Parameters:
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.
- Parameters:
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.
- Parameters:
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.
- Parameters:
obj
-
the object to compare with
- Returns:
- true if the objects are the same; false otherwise.
- Overrides:
- equals in class Object (I-§1.12.3).
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
as its top-left corner, a width of
and a height of
- Parameters:
h
-
the horizontal expansion
v
-
the vertical expansion
hashCode
public int hashCode()
- Returns:
- a hash code value for this object.
- Overrides:
- hashCode in class Object (I-§1.12.6).
inside
public boolean inside(int x, int y)
- Checks if the specified point lies inside this rectangle.
- Parameters:
x
-
the x coordinate
y
-
the y coordinate
- Returns:
- true if the point
is inside this rectangle; false otherwise.
intersection
public Rectangle intersection(Rectangle r)
- Parameters:
r
-
a rectangle
- Returns:
- the largest rectangle contained in both the rectangle argument and in
this 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.
- Parameters:
r
-
a rectangle
- Returns:
- true if the rectangle argument and this rectangle insersect; false otherwise.
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.
- 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
coordinate.
- Parameters:
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
coordinate and its new width and height are the specified arguments.
- Parameters:
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.
- Parameters:
width
-
the new width
height
-
the new height
toString
public String toString()
- Returns:
- a string representation of this rectangle.
- Overrides:
- toString in class Object (I-§1.12.9).
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
, where it had been the point
.
- Parameters:
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.
- Parameters:
r
-
a rectangle
- Returns:
- the smallest rectangle containing both the rectangle argument and this
rectangle.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com