|
Chapter 19 java.awt Reference |
|
Rectangle
Name
Rectangle
The Rectangle class represents
a rectangle by combining its origin (a pair of x and y coordinates) with
its size (a width and a height).
public class java.awt.Rectangle
extends java.lang.Object
implements java.awt.Shape, java.io.Serializable {
// Variables
pubic int height;
public int width;
public int x;
public int y;
// Constructors
public Rectangle();
public Rectangle (int width, int height);
public Rectangle (int x, int y, int width, int height);
public Rectangle (Dimension d);
public Rectangle (Point p);
public Rectangle (Point p, Dimension d);
public Rectangle (Rectangle r);
// Instance Methods
public void add (int newX, int newY);
public void add (Point p);
public void add (Rectangle r);
public boolean contains (int x, int y);
public boolean contains (Point p);
public boolean equals (Object object);
public Rectangle getBounds();
public Point getLocation();
public Dimension getSize();
public void grow (int horizontal, int vertical);
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 void setBounds (Rectangle r);
public void setBounds (int x, int y, int width, int height);
public void setLocation (int x, int y);
public void setLocation (Point p);
public void setSize (int width, int height);
public void setSize (Dimension d);
public String toString();
public void translate (int x, int y);
public Rectangle union (Rectangle r);
}
The height of the Rectangle.
The width of the Rectangle.
The x coordinate of the Rectangle's
upper left corner (its origin).
The y coordinate of the Rectangle's
upper left corner (its origin).
- Description
-
Constructs an empty Rectangle
object with an origin of (0, 0) and dimensions of 0 x 0.
- Parameters
-
- width
-
width of Rectangle
- height
-
height of Rectangle
- Description
-
Constructs a Rectangle object
with an origin of (0, 0) and dimensions of width
x height.
- Parameters
-
- x
-
x coordinate of the Rectangle's
origin
- y
-
y coordinate of the Rectangle's
origin
- width
-
width of Rectangle
- height
-
height of Rectangle
- Description
-
Constructs a Rectangle object
with an origin of (x, y)
and dimensions of width x height.
- Parameters
-
- d
-
dimensions of Rectangle
- Description
-
Constructs a Rectangle object
with an origin of (0, 0) and dimensions of d.width
x d.height.
- Parameters
-
- p
-
origin of Rectangle
- Description
-
Constructs an empty Rectangle
object with an origin of (p.x,
p.y) and dimensions of 0 x
0.
- Parameters
-
- p
-
origin of Rectangle
- d
-
dimensions of Rectangle
- Description
-
Constructs a Rectangle object
with an origin of (p.x, p.y)
and dimensions of d.width x
d.height.
- Parameters
-
- r
-
original Rectangle
- Description
-
Constructs copy of the given Rectangle.
- Parameters
-
- newX
-
The x-coordinate of
a point to incorporate within the Rectangle.
- newY
-
The y-coordinate of
a point to incorporate within the Rectangle.
- Description
-
Extends the Rectangle so that
the point (newX, newY)
is within it.
- Parameters
-
- p
-
The new Point
to add to the Rectangle.
- Description
-
Extends the Rectangle so that
the point p is within it.
- Parameters
-
- r
-
The Rectangle
being added to the current Rectangle.
- Description
-
Extends the Rectangle to include
the Rectangle r.
- Parameters
-
- x
-
The x coordinate to test.
- y
-
The y coordinate to test.
- Returns
-
true if the Rectangle
contains the point; false otherwise.
- Parameters
-
- p
-
The point to be tested.
- Returns
-
true if the Rectangle
contains the point; false otherwise.
- Parameters
-
- object
-
The object to compare.
- Returns
-
true if both Rectangles
have the same origin, width, and height; false
otherwise.
- Overrides
-
Object.equals(Object)
- Description
-
Compares two different Rectangle
instances for equivalence.
- Implements
-
Shape.getBounds()
- Returns
-
Bounding Rectangle.
- Returns
-
Position of the rectangle.
- Description
-
Gets the current position of this Rectangle.
- Returns
-
Dimensions of the rectangle.
- Description
-
Gets width and height of the rectangle.
- Parameters
-
- horizontal
-
Amount to extend
Rectangle in horizontal direction
on both the left and right sides.
- vertical
-
Amount to extend
Rectangle in vertical direction
on both the top and the bottom.
- Description
-
Increases the rectangle's dimensions.
- Returns
-
A hashcode to use when using the Rectangle
as a key in a Hashtable.
- Overrides
-
Object.hashCode()
- Description
-
Generates a hashcode for the Rectangle.
- Parameters
-
- x
-
The x coordinate to check.
- y
-
The y coordinate to check.
- Returns
-
true if (x,
y) falls within the Rectangle,
false otherwise.
- Description
-
Checks to see if the point (x,
y) is within the Rectangle.
Replaced by contains(int, int).
- Parameters
-
- r
-
Rectangle
to add to the current Rectangle.
- Returns
-
A new Rectangle consisting
of all points in both the current Rectangle
and r.
- Description
-
Generates a new Rectangle that
is the intersection of r and
the current Rectangle.
- Parameters
-
- r
-
Rectangle
to check.
- Returns
-
true if any points in r
are also in the current Rectangle,
false otherwise.
- Description
-
Checks to see if r crosses
the Rectangle.
- Returns
-
true if the Rectangle
is empty, false otherwise.
- Description
-
Determines if the rectangle is dimensionless (i.e., width or height are
less than or equal to 0).
- Parameters
-
- x
-
The new x coordinate of
the Rectangle's upper
left corner.
- y
-
The new y coordinate of
the Rectangle's upper
left corner.
- Description
-
Changes the Rectangle's
origin to (x, y).
Replaced by setLocation(int, int).
- Parameters
-
- x
-
The new x coordinate of
the Rectangle's upper
left corner.
- y
-
The new y coordinate of
the Rectangle's upper
left corner.
- width
-
The new width.
- height
-
The new height.
- Description
-
Changes Rectangle's origin
and dimensions. Replaced by setBounds(int, int, int,
int).
- Parameters
-
- width
-
The new width.
- height
-
The new height.
- Description
-
Changes Rectangle's dimensions.
Replaced by setSize(int, int).
- Parameters
-
- r
-
A Rectangle
describing the new bounds.
- Description
-
Changes Rectangle's location
and size.
- Parameters
-
- x
-
The new x coordinate of
the Rectangle's upper
left corner.
- y
-
The new y coordinate of
the Rectangle's upper
left corner.
- width
-
The new width.
- height
-
The new height.
- Description
-
Changes Rectangle's location
and size.
- Parameters
-
- x
-
New horizontal position.
- y
-
New vertical position.
- Description
-
Relocates the rectangle.
- Parameters
-
- p
-
New position for component.
- Description
-
Relocates the rectangle.
- Parameters
-
- width
-
New width.
- height
-
New height.
- Description
-
Resizes the rectangle.
- Parameters
-
- d
-
New dimensions.
- Description
-
Resizes the rectangle.
- Returns
-
A string representation of the Rectangle
object.
- Overrides
-
Object.toString()
- Parameters
-
- deltax
-
Amount to move Rectangle
horizontally.
- deltay
-
Amount to move Rectangle
vertically.
- Description
-
Moves the Rectangle's
origin to (x+deltax, y+deltay).
- Parameters
-
- r
-
Rectangle to determine
union with.
- Returns
-
The smallest Rectangle containing
both r and the current Rectangle.
- Description
-
Generates a new Rectangle by
combining r and the current
Rectangle.
Dimension, Object,
Point, String
|