| |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
java.awt
类 Rectangle
java.lang.Object java.awt.geom.RectangularShape java.awt.geom.Rectangle2D java.awt.Rectangle
- 所有已实现的接口:
- Shape, Serializable, Cloneable
- 直接已知子类:
- DefaultCaret
public class Rectangle
- extends Rectangle2D
- implements Shape, Serializable
Rectangle
指定了坐标空间中的一个区域,通过 Rectangle
对象的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。
Rectangle
对象的 width
和 height
是 public
字段。创建 Rectangle
的构造方法,以及可以修改该对象的方法,都不会禁止将 width 或 height 设置为负值。
如果 Rectangle
的 width 或 height 为负值,则认为 Rectangle 为空。如果 Rectangle
为空,则 isEmpty
方法将返回 true
。空 Rectangle
中不包含任何点,或者说其内部没有任何点。但是,width
和 height
的值仍然有效。空 Rectangle
在坐标空间中仍有一个位置,改变其大小或位置的方法仍然有效。如果任何参与操作的 Rectangle
对象有一个负的 width
或 height
,则对过个 Rectangle
进行操作的方法的行为是不确定的。这些方法包括 intersects
、intersection
和 union
。
- 从以下版本开始:
- JDK1.0
- 另请参见:
- 序列化表格
嵌套类摘要 |
---|
从类 java.awt.geom.Rectangle2D 继承的嵌套类/接口 |
---|
Rectangle2D.Double, Rectangle2D.Float |
字段摘要 | |
---|---|
int | height Rectangle 的高度。 |
int | width Rectangle 的宽度。 |
int | x Rectangle 的 x 坐标。 |
int | y Rectangle 的 y 坐标。 |
从类 java.awt.geom.Rectangle2D 继承的字段 |
---|
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP |
构造方法摘要 | |
---|---|
Rectangle() 构造一个新的 Rectangle ,其左上角的坐标为(0,0),宽度和高度均为零。 | |
Rectangle(Dimension d) 构造一个新的 Rectangle ,其左上角为(0,0),其宽度和高度由 Dimension 参数指定。 | |
Rectangle(int width, int height) 构造一个新的 Rectangle ,其左上角的坐标为(0,0),而其宽度和高度由同名的参数指定。 | |
Rectangle(int x, int y, int width, int height) 构造一个新的 Rectangle ,其左上角被指定为(x ,y ),而其宽度和高度由同名称的参数指定。 | |
Rectangle(Point p) 构造一个新的 Rectangle ,其左上顶点是指定的 Point ,并且其宽度和高度均为零。 | |
Rectangle(Point p, Dimension d) 构造一个新的 Rectangle ,其左上角由 Point 参数指定,其宽度和高度由 Dimension 参数指定。 | |
Rectangle(Rectangle r) 构造一个新的 Rectangle ,并将其初始化,以匹配指定 Rectangle 的值。 |
方法摘要 | |
---|---|
void | add(int newx, int newy) 将一个点添加到此 Rectangle ,这个点由整数参数 newx 和 newy 指定。 |
void | add(Point pt) 将指定的 Point 添加到此 Rectangle 中。 |
void | add(Rectangle r) 将一个 Rectangle 添加到此 Rectangle 中。 |
boolean | contains(int x, int y) 检查此 Rectangle 是否包含指定位置的点(x,y)。 |
boolean | contains(int X, int Y, int W, int H) 检查此 Rectangle 是否完整地包含指定位置(X,Y)上具有指定尺寸(W,H)的 Rectangle 。 |
boolean | contains(Point p) 检查此 Rectangle 是否包含指定的 Point 。 |
boolean | contains(Rectangle r) 检查此 Rectangle 是否完整地包含指定的 Rectangle 。 |
Rectangle2D | createIntersection(Rectangle2D r) 返回一个新的 Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的交集。 |
Rectangle2D | createUnion(Rectangle2D r) 返回一个新的 Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的并集。 |
boolean | equals(Object obj) 检查两个矩形是否相等。 |
Rectangle | getBounds() 获得此 Rectangle 的边界 Rectangle 。 |
Rectangle2D | getBounds2D() 返回此 rectangle 的高精度边界框。 |
double | getHeight() 以 double 精度形式返回边界 Rectangle 的高度。 |
Point | getLocation() 返回此 Rectangle 的位置。 |
Dimension | getSize() 获得此 Rectangle 的大小,用返回的 Dimension 表示。 |
double | getWidth() 以 double 精度形式返回边界 Rectangle 的宽度。 |
double | getX() 以 double 精度形式返回边界 Rectangle 的 X 坐标。 |
double | getY() 以 double 精度形式返回边界 Rectangle 的 Y 坐标。 |
void | grow(int h, int v) 在水平方向和垂直方向上重新设置 Rectangle 的大小。 |
boolean | inside(int X, int Y) 已过时。 从 JDK version 1.1 开始,由 contains(int, int) 取代。 |
Rectangle | intersection(Rectangle r) 计算此 Rectangle 与指定 Rectangle 的交集。 |
boolean | intersects(Rectangle r) 确定此 Rectangle 是否与指定 Rectangle 相交。 |
boolean | isEmpty() 确定此 Rectangle 是否为空。 |
void | move(int x, int y) 已过时。 从 JDK version 1.1 开始,由 setLocation(int, int) 取代。 |
int | outcode(double x, double y) 确定指定坐标相对于此 Rectangle 的位置。 |
void | reshape(int x, int y, int width, int height) 已过时。 从 JDK version 1.1 开始,由 setBounds(int, int, int, int) 取代。 |
void | resize(int width, int height) 已过时。 从 JDK version 1.1 开始,由 setSize(int, int) 取代。 |
void | setBounds(int x, int y, int width, int height) 将此 Rectangle 的边界 Rectangle 设置为指定的 x 、y 、width 和 height 。 |
void | setBounds(Rectangle r) 设置此 Rectangle 的边界 Rectangle ,以匹配指定的 Rectangle 。 |
void | setLocation(int x, int y) 将此 Rectangle 移动到指定位置。 |
void | setLocation(Point p) 将此 Rectangle 移动到指定位置。 |
void | setRect(double x, double y, double width, double height) 将此 Rectangle 的边界设置为指定的 x 、y 、width 和 height 。 |
void | setSize(Dimension d) 设置此 Rectangle 的大小,以匹配指定的 Dimension 。 |
void | setSize(int width, int height) 将此 Rectangle 的大小设置为指定的宽度和高度。 |
String | toString() 返回表示此 Rectangle 及其值的 String 。 |
void | translate(int x, int y) 将此 Rectangle 沿 x 坐标轴向右,沿 y 坐标轴向下移动指定距离。 |
Rectangle | union(Rectangle r) 计算此 Rectangle 与指定 Rectangle 的并集。 |
从类 java.awt.geom.Rectangle2D 继承的方法 |
---|
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union |
从类 java.awt.geom.RectangularShape 继承的方法 |
---|
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal |
从类 java.lang.Object 继承的方法 |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
从接口 java.awt.Shape 继承的方法 |
---|
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects |
字段详细信息 |
---|
x
public int x
Rectangle
的 x 坐标。
y
public int y
Rectangle
的 y 坐标。
width
public int width
Rectangle
的宽度。- 从以下版本开始:
- JDK1.0.
- 另请参见:
setSize(int, int)
,getSize()
height
public int height
Rectangle
的高度。- 另请参见:
setSize(int, int)
,getSize()
构造方法详细信息 |
---|
Rectangle
public Rectangle()
- 构造一个新的
Rectangle
,其左上角的坐标为(0,0),宽度和高度均为零。
Rectangle
public Rectangle(Rectangle r)
- 构造一个新的
Rectangle
,并将其初始化,以匹配指定Rectangle
的值。- 参数:
r
- 一个Rectangle
,要从中将初始值复制到新构造的Rectangle
- 从以下版本开始:
- JDK1.1
Rectangle
public Rectangle(int x, int y, int width, int height)
- 构造一个新的
Rectangle
,其左上角被指定为(x
,y
),而其宽度和高度由同名称的参数指定。- 参数:
x
- 指定的 x 坐标y
- 指定的 y 坐标width
-Rectangle
的宽度height
-Rectangle
的高度
Rectangle
public Rectangle(int width, int height)
- 构造一个新的
Rectangle
,其左上角的坐标为(0,0),而其宽度和高度由同名的参数指定。- 参数:
width
-Rectangle
的宽度height
-Rectangle
的高度