public class GRectangle extends Object implements Serializable
Rectangle class
in java.awt.| Constructor and Description |
|---|
GRectangle()
Constructs a new empty
GRectangle. |
GRectangle(float width,
float height)
Constructs a
GRectangle at the origin with the specified width and height. |
GRectangle(float x,
float y,
float width,
float height)
Constructs a new
GRectangle with the specified coordinates and size. |
GRectangle(GDimension size)
Constructs a new
GRectangle at the origin with the specified size. |
GRectangle(GPoint pt)
Constructs a new empty
GRectangle at the specified location. |
GRectangle(GPoint pt,
GDimension size)
Constructs a new
GRectangle with the specified location and size. |
GRectangle(GRectangle r)
Constructs a new
GRectangle from an existing one. |
| Modifier and Type | Method and Description |
|---|---|
GRectangle |
add(float x,
float y)
Adds the specified point to the rectangle.
|
GRectangle |
add(GRectangle r)
Adjusts the bounds of the current
GRectangle so that it contains
the rectangle represented by the argument. |
boolean |
contains(float x,
float y)
Returns
true if the GRectangle contains the specified point. |
boolean |
contains(GPoint pt)
Returns
true if the GRectangle contains the specified point. |
boolean |
equals(Object obj)
Tests whether two
GRectangle objects are equal. |
GRectangle |
getBounds()
Returns a new
GRectangle whose bounds are the same as this one. |
float |
getHeight()
Returns the height of this
GDimension. |
GPoint |
getLocation()
Returns a new
GPoint with the location of the rectangle. |
GDimension |
getSize()
Returns a new
GDimension object with the size of the GRectangle. |
float |
getWidth()
Returns the width of this
GDimension. |
float |
getX()
Returns the x coordinate of this
GRectangle. |
float |
getY()
Returns the y coordinate of this
GRectangle. |
GRectangle |
grow(float dx,
float dy)
Adjusts the edges of a rectangle by the specified
dx and dy
offsets along each of its borders. |
int |
hashCode()
Returns an integer hash code for the rectangle.
|
GRectangle |
intersection(GRectangle r2)
Returns the largest rectangle that is contained in both
r1 and r2. |
boolean |
intersects(GRectangle r2)
Returns
true if r1 and r2 have a nonempty
intersection. |
boolean |
isEmpty()
Returns
true if the rectangle is empty. |
GRectangle |
setBounds(float x,
float y,
float width,
float height)
Sets the components of a
GRectangle from the specified values. |
GRectangle |
setBounds(GPoint pt,
GDimension size)
Sets the components of a
GRectangle from the specified location and size. |
GRectangle |
setBounds(GRectangle bounds)
Sets the bounds of one
GRectangle equal to that of another. |
GRectangle |
setLocation(float x,
float y)
Sets the location of the
GRectangle to the specified x
and y values. |
GRectangle |
setLocation(GPoint pt)
Sets the location of the
GRectangle to the specified point. |
GRectangle |
setSize(float width,
float height)
Sets the size of the
GRectangle to the specified values. |
GRectangle |
setSize(GDimension size)
Sets the size of the
GRectangle to the specified dimension. |
String |
toString()
Converts this
GRectangle to its string representation. |
GRectangle |
translate(float dx,
float dy)
Adjusts the coordinates of a rectangle by the specified
dx and
dy offsets. |
GRectangle |
union(GRectangle r2)
Returns the smallest rectangle that contains both
r1 and r2. |
public GRectangle()
GRectangle.public GRectangle(float x,
float y,
float width,
float height)
GRectangle with the specified coordinates and size.x - The x-coordinate of the rectangley - The y-coordinate of the rectanglewidth - The width of the rectangleheight - The height of the rectanglepublic GRectangle(float width,
float height)
GRectangle at the origin with the specified width and height.width - The width of the rectangleheight - The height of the rectanglepublic GRectangle(GPoint pt, GDimension size)
GRectangle with the specified location and size.pt - The location of the upper left corner of the rectanglesize - The dimensions of the rectanglepublic GRectangle(GPoint pt)
GRectangle at the specified location.pt - The location of the upper left corner of the rectanglepublic GRectangle(GDimension size)
GRectangle at the origin with the specified size.size - The dimensions of the rectanglepublic GRectangle(GRectangle r)
GRectangle from an existing one.r - The original rectanglepublic float getX()
GRectangle.GRectanglepublic float getY()
GRectangle.GRectanglepublic float getWidth()
GDimension.GDimensionpublic float getHeight()
GDimension.GDimensionpublic GRectangle setBounds(float x, float y, float width, float height)
GRectangle from the specified values.x - The x-coordinate of the rectangley - The y-coordinate of the rectanglewidth - The width of the rectangleheight - The height of the rectanglepublic GRectangle setBounds(GPoint pt, GDimension size)
GRectangle from the specified location and size.pt - The location of the upper left corner of the rectanglesize - The dimensions of the rectanglepublic GRectangle setBounds(GRectangle bounds)
GRectangle equal to that of another.bounds - A GRectangle specifying the new boundspublic GRectangle getBounds()
GRectangle whose bounds are the same as this one.public GRectangle setLocation(float x, float y)
GRectangle to the specified x
and y values.x - The new x-coordinate for the rectangley - The new y-coordinate for the rectanglepublic GRectangle setLocation(GPoint pt)
GRectangle to the specified point.pt - The new location for the rectanglepublic GPoint getLocation()
GPoint with the location of the rectangle.GPointpublic GRectangle translate(float dx, float dy)
dx and
dy offsets.dx - The change in the x direction (positive is rightward)dy - The change in the y direction (positive is downward)public GRectangle setSize(float width, float height)
GRectangle to the specified values.width - The new width of the rectangleheight - The new height of the rectanglepublic GRectangle setSize(GDimension size)
GRectangle to the specified dimension.size - The new dimensions of the rectanglepublic GDimension getSize()
GDimension object with the size of the GRectangle.GDimensionpublic GRectangle grow(float dx, float dy)
dx and dy
offsets along each of its borders.dx - The offset to extend each of the left and right bordersdy - The offset to extend each of the top and bottom borderspublic boolean isEmpty()
true if the rectangle is empty.true if the rectangle is empty, and false otherwisepublic boolean contains(float x,
float y)
true if the GRectangle contains the specified point.x - The x-coordinate of the point being testedy - The y-coordinate of the point being testedtrue if the rectangle contains (x, y),
and false otherwisepublic boolean contains(GPoint pt)
true if the GRectangle contains the specified point.pt - The point being testedtrue if the rectangle contains pt,
and false otherwisepublic boolean intersects(GRectangle r2)
true if r1 and r2 have a nonempty
intersection.r2 - A second rectangletrue if the two rectangles intersect, and false otherwisepublic GRectangle intersection(GRectangle r2)
r1 and r2.r2 - A second rectangler2public GRectangle union(GRectangle r2)
r1 and r2.r2 - A second rectangler2public GRectangle add(GRectangle r)
GRectangle so that it contains
the rectangle represented by the argument.r - A new rectangle to include in this onepublic GRectangle add(float x, float y)
x - The x coordinate of the new pointy - The y coordinate of the new pointpublic int hashCode()
GRectangle is constructed from the hash codes from the
float values of the coordinates, which are the ones used in the
equals method.hashCode in class ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public boolean equals(Object obj)
GRectangle objects are equal.
Because floating-point values are inexact, this method checks for
equality by comparing the float values (rather than the
float values) of the coordinates.equals in class Objectobj - Any objecttrue if the obj is a GRectangle
equal to this one, and false otherwiseObject.hashCode(),
HashMap