Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.awt.geom.RectangularShape | +----java.awt.geom.Rectangle2D | +----java.awt.Rectangle
A rectangle's width
and height
are
public fields. The constructors that allow you to create a
rectangle, and the methods that allow you to modify one, do not
prevent you from setting a negative value for width or height.
A rectangle whose width or height is negative is considered
empty, and all methods defined by the Rectangle
class
behave accordingly. If the rectangle is empty, then the method
isEmpty
returns true
. No point can be
contained by or inside an empty rectangle, however the values of
width
and height
are still valid. An
empty rectangle still has a location in the coordinate space, and
methods that change its size or location remain valid. The
behavior of methods that operate on more than one rectangle is
undefined if any of the participating rectangles has a negative
width
or height
. These methods include
intersects
, intersection
, and
union
.
specified in integer coordinates.
Inner classes inherited from class java.awt.geom.Rectangle2D |
Rectangle2D.Double, Rectangle2D.Float |
Field Summary | |
int | height
|
int | width
|
int | x
|
int | y
|
Fields inherited from class java.awt.geom.Rectangle2D |
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP |
Constructor Summary | |
Rectangle()
|
|
Rectangle(Rectangle r)
|
|
Rectangle(int x,
int y,
int width,
int height)
x , y ) and whose width and height
are specified by the arguments of the same name.
|
|
Rectangle(int width,
int height)
|
|
Rectangle(Point p,
Dimension d)
point argument, and whose width and height
are specified by the dimension argument.
|
|
Rectangle(Point p)
|
|
Rectangle(Dimension d)
dimension argument.
|
Method Summary | |
void | add(int newx,
int newy)
newx
and newy , to this rectangle.
|
void | add(Point pt)
pt to this rectangle.
|
void | add(Rectangle r)
|
boolean | contains(Point p)
|
boolean | contains(int x,
int y)
|
boolean | contains(Rectangle r)
|
boolean | contains(int X,
int Y,
int W,
int H)
|
Rectangle2D | createIntersection(Rectangle2D r)
|
Rectangle2D | createUnion(Rectangle2D r)
|
boolean | equals(Object obj)
|
Rectangle | getBounds()
|
double | getHeight()
|
Point | getLocation()
|
Dimension | getSize()
|
double | getWidth()
|
double | getX()
|
double | getY()
|
void | grow(int h,
int v)
|
int | hashCode()
|
boolean | inside(int x,
int y)
|
Rectangle | intersection(Rectangle r)
|
boolean | intersects(Rectangle r)
|
boolean | isEmpty()
|
void | move(int x,
int y)
|
int | outcode(double x,
double y)
|
void | reshape(int x,
int y,
int width,
int height)
|
void | resize(int width,
int height)
|
void | setBounds(Rectangle r)
|
void | setBounds(int x,
int y,
int width,
int height)
x , y , width ,
and height .
|
void | setLocation(Point p)
|
void | setLocation(int x,
int y)
|
void | setRect(double x,
double y,
double width,
double height)
|
void | setSize(Dimension d)
|
void | setSize(int width,
int height)
|
String | toString()
|
void | translate(int x,
int y)
|
Rectangle | union(Rectangle r)
|
Methods inherited from class java.awt.geom.Rectangle2D |
add, add, add, contains, contains, createIntersection, createUnion, equals, getBounds2D, getPathIterator, getPathIterator, intersect, intersects, intersectsLine, intersectsLine, outcode, outcode, setBounds, setRect, setRect, union |
Methods inherited from class java.awt.geom.RectangularShape |
clone, contains, contains, getBottom, getBounds, getCenterX, getCenterY, getHeight, getLeft, getPathIterator, getRight, getTop, getWidth, getX, getY, intersects, isEmpty, setBounds, setBounds, setBounds, setBoundsFromCenter, setBoundsFromCenter, setBoundsFromDiagonal, setBoundsFromDiagonal |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public int x
public int y
public int width
public int height
Constructor Detail |
public Rectangle()
public Rectangle(Rectangle r)
r
- a rectangle from which to copy initial values.
public Rectangle(int x, int y, int width, int height)
x
, y
) and whose width and height
are specified by the arguments of the same name.
x
- the x coordinate.
y
- the y coordinate.
width
- the width of the rectangle.
height
- the height of the rectangle.
public Rectangle(int width, int height)
width
- the width of the rectangle.
height
- the height of the rectangle.
public Rectangle(Point p, Dimension d)
point
argument, and whose width and height
are specified by the dimension
argument.
p
- a point, the top-left corner of the rectangle.
d
- a dimension, representing the width and height.
public Rectangle(Point p)
p
- the top left corner of the rectangle.
public Rectangle(Dimension d)
dimension
argument.
d
- a dimension, specifying width and height.
Method Detail |
public double getX()
public double getY()
public double getWidth()
public double getHeight()
public Rectangle getBounds()
This method is included for completeness, to parallel the
getBounds
method of Component
.
public void setBounds(Rectangle r)
This method is included for completeness, to parallel the
setBounds
method of Component
.
r
- a rectangle.
public void setBounds(int x, int y, int width, int height)
x
, y
, width
,
and height
.
This method is included for completeness, to parallel the
setBounds
method of Component
.
x
- the new x coordinate for the top-left
corner of this rectangle.
y
- the new y coordinate for the top-left
corner of this rectangle.
width
- the new width for this rectangle.
height
- the new height for this rectangle.
public void setRect(double x, double y, double width, double height)
width
- the new width for the Dimension object
height
- the new height for the Dimension object
public void reshape(int x, int y, int width, int height)
setBounds(int, int, int, int)
.
public Point getLocation()
This method is included for completeness, to parallel the
getLocation
method of Component
.
public void setLocation(Point p)
This method is included for completeness, to parallel the
setLocation
method of Component
.
p
- the new location for the point.
public void setLocation(int x, int y)
This method is included for completeness, to parallel the
setLocation
method of Component
.
x
- the x coordinate of the new location.
y
- the y coordinate of the new location.
public void move(int x, int y)
setLocation(int, int)
.
public void translate(int x, int y)
dx
- the distance to move the rectangle
along the x axis.
dy
- the distance to move the rectangle
along the y axis.
public Dimension getSize()
This method is included for completeness, to parallel the
getSize
method of Component
.
public void setSize(Dimension d)
This method is included for completeness, to parallel the
setSize
method of Component
.
d
- the new size for the Dimension object
public void setSize(int width, int height)
This method is included for completeness, to parallel the
setSize
method of Component
.
width
- the new width for this rectangle object.
height
- the new height for this rectangle object.
public void resize(int width, int height)
setSize(int, int)
.
public boolean contains(Point p)
p
- the point (location) to test.
true
if the point
(x, y) is inside this rectangle;
false
otherwise.public boolean contains(int x, int y)
x
- the x coordinate.
y
- the y coordinate.
true
if the point
(x, y) is inside this rectangle;
false
otherwise.public boolean contains(Rectangle r)
r
- the rectangle.
true
if the rectangle (r)
is contained entirely inside this rectangle;
false
otherwise.public boolean contains(int X, int Y, int W, int H)
X
- the x coordinate.
Y
- the y coordinate.
W
- the width of the rectangle.
H
- the height of the rectangle.
true
if the rectangle specified by
(X, Y, W, H)
is entirely enclosed inside this rectangle;
false
otherwise.public boolean inside(int x, int y)
contains(int, int)
.
public boolean intersects(Rectangle r)
r
- a rectangle.
true
if the specified rectangle
and this rectangle insersect;
false
otherwise.public Rectangle intersection(Rectangle r)
r
- a rectangle.
public Rectangle union(Rectangle r)
r
- a rectangle.
public void add(int newx, int newy)
newx
and newy
, to this rectangle. The resulting rectangle is
the smallest rectangle that contains both the original rectangle
and the specified point.
After adding a point, a call to contains
with the
added point as an argument will not necessarily return
true
. The contains
method does not
return true
for points on the right or bottom
edges of a rectangle. Therefore if the added point falls on
the right or bottom edge of the enlarged rectangle,
contains
will return false
for that point.
newx
- the x coordinate of the new point.
newy
- the y coordinate of the new point.
public void add(Point pt)
pt
to this rectangle. The resulting
rectangle is the smallest rectangle that contains both the
original rectangle and the specified point.
After adding a point, a call to contains
with the
added point as an argument will not necessarily return
true
. The contains
method does not
return true
for points on the right or bottom
edges of a rectangle. Therefore if the added point falls on
the right or bottom edge of the enlarged rectangle,
contains
will return false
for that point.
pt
- the new point to add to the rectangle.
public void add(Rectangle r)
a
- rectangle.
public void grow(int h, int v)
This method modifies the rectangle so that it is
h
units larger on both the left and right side,
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
width
+
2h
,
and a height of
height
+
2v
.
If negative values are supplied for h
and
v
, the size of the rectangle decreases accordingly.
The grow
method does not check whether the resulting
values of width
and height
are
non-negative.
h
- the horizontal expansion.
v
- the vertical expansion.
public boolean isEmpty()
true
if this rectangle is empty;
false
otherwise.public int outcode(double x, double y)
public Rectangle2D createIntersection(Rectangle2D r)
r
- the rectangle to be intersected with
public Rectangle2D createUnion(Rectangle2D r)
r
- the rectangle to be combined with
public int hashCode()
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 rectangle.
obj
- the object to compare with.
true
if the objects are equal;
false
otherwise.public String toString()
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |