|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.geom.RectangularShape
java.awt.geom.Rectangle2D
java.awt.Rectangle
public class Rectangle
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。
| 嵌套类摘要 |
|---|
| 从类 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 |
| 字段详细信息 |
|---|
public int x
Rectangle 的 x 坐标。
setLocation(int, int),
getLocation()public int y
Rectangle 的 y 坐标。
setLocation(int, int),
getLocation()public int width
Rectangle 的宽度。
setSize(int, int),
getSize()public int height
Rectangle 的高度。
setSize(int, int),
getSize()| 构造方法详细信息 |
|---|
public Rectangle()
Rectangle,其左上角的坐标为(0,0),宽度和高度均为零。
public Rectangle(Rectangle r)
Rectangle,并将其初始化,以匹配指定 Rectangle 的值。
r - 一个 Rectangle,要从中将初始值复制到新构造的 Rectangle
public Rectangle(int x,
int y,
int width,
int height)
Rectangle,其左上角被指定为(x,y),而其宽度和高度由同名称的参数指定。
x - 指定的 x 坐标y - 指定的 y 坐标width - Rectangle 的宽度height - Rectangle 的高度
public Rectangle(int width,
int height)
Rectangle,其左上角的坐标为(0,0),而其宽度和高度由同名的参数指定。
width - Rectangle 的宽度height - Rectangle 的高度
public Rectangle(Point p,
Dimension d)
Rectangle,其左上角由 Point 参数指定,其宽度和高度由 Dimension 参数指定。
p - 一个 Point,它是 Rectangle 的左上角d - 一个 Dimension,表示 Rectangle 的宽度和高度public Rectangle(Point p)
Rectangle,其左上顶点是指定的 Point,并且其宽度和高度均为零。
p - 一个 Point,它是 Rectangle 的左上顶点public Rectangle(Dimension d)
Rectangle,其左上角为(0,0),其宽度和高度由 Dimension 参数指定。
d - 一个 Dimension,用于指定宽度和高度| 方法详细信息 |
|---|
public double getX()
double 精度形式返回边界 Rectangle 的 X 坐标。
RectangularShape 中的 getXRectangle 的 x 坐标。public double getY()
double 精度形式返回边界 Rectangle 的 Y 坐标。
RectangularShape 中的 getYRectangle 的 y 坐标。public double getWidth()
double 精度形式返回边界 Rectangle 的宽度。
RectangularShape 中的 getWidthRectangle 的宽度。public double getHeight()
double 精度形式返回边界 Rectangle 的高度。
RectangularShape 中的 getHeightRectangle 的高度。public Rectangle getBounds()
Rectangle 的边界 Rectangle。
包含此方法是出于完整性考虑,它与 Component 的 getBounds 方法相似。
Shape 中的 getBoundsRectangularShape 中的 getBoundsRectangle,它等同于此 Rectangle 的边界 Rectangle。Component.getBounds(),
setBounds(Rectangle),
setBounds(int, int, int, int)public Rectangle2D getBounds2D()
Shape 中的 getBounds2DRectangle2D 中的 getBounds2DRectangle2D 的边界框。Shape.getBounds()public void setBounds(Rectangle r)
Rectangle 的边界 Rectangle,以匹配指定的 Rectangle。
包含此方法是出于完整性考虑,它与 Component 的 setBounds 方法相似。
r - 指定的 RectanglegetBounds(),
Component.setBounds(java.awt.Rectangle)
public void setBounds(int x,
int y,
int width,
int height)
Rectangle 的边界 Rectangle 设置为指定的 x、y、width 和 height。
包含此方法是出于完整性考虑,它与 Component 的 setBounds 方法相似。
x - 此 Rectangle 的左上角的新 x 坐标y - 此 Rectangle 的左上角的新 y 坐标width - 此 Rectangle 的新宽度height - 此 Rectangle 的新高度getBounds(),
Component.setBounds(int, int, int, int)
public void setRect(double x,
double y,
double width,
double height)
Rectangle 的边界设置为指定的 x、y、width 和 height。包含此方法是出于完整性考虑,它与 Component 的 setBounds 方法相似。
Rectangle2D 中的 setRectx - 指定矩形的左上角的 x 坐标y - 指定矩形的左上角的 y 坐标width - Dimension 对象的新宽度height - Dimension 对象的新高度
@Deprecated
public void reshape(int x,
int y,
int width,
int height)
setBounds(int, int, int, int) 取代。
Rectangle 的边界 Rectangle 设置为指定的 x、y、width 和 height。
x - 此 Rectangle 的左上角的新 x 坐标y - 此 Rectangle 的左上角的新 y 坐标width - 此 Rectangle 的新宽度height - 此 Rectangle 的新高度public Point getLocation()
Rectangle 的位置。
包含此方法是出于完整性考虑,它与 Component 的 getLocation 方法相似。
Point,它是此 Rectangle 的左上角。Component.getLocation(),
setLocation(Point),
setLocation(int, int)public void setLocation(Point p)
Rectangle 移动到指定位置。
包含此方法是出于完整性考虑,它与 Component 的 setLocation 方法相似。
p - 为此 Rectangle 指定新位置的 PointComponent.setLocation(java.awt.Point),
getLocation()
public void setLocation(int x,
int y)
Rectangle 移动到指定位置。
包含此方法是出于完整性考虑,它与 Component 的 setLocation 方法相似。
x - 新位置的 x 坐标y - 新位置的 y 坐标getLocation(),
Component.setLocation(int, int)
@Deprecated
public void move(int x,
int y)
setLocation(int, int) 取代。
Rectangle 移动到指定位置。
x - 新位置的 x 坐标y - 新位置的 y 坐标
public void translate(int x,
int y)
Rectangle 沿 x 坐标轴向右,沿 y 坐标轴向下移动指定距离。
x - 沿 x 坐标轴移动此 Rectangle 的距离y - 沿 y 坐标轴移动此 Rectangle 的距离setLocation(int, int),
setLocation(java.awt.Point)public Dimension getSize()
Rectangle 的大小,用返回的 Dimension 表示。
包含此方法是出于完整性考虑,它与 Component 的 getSize 方法相似。
Dimension,表示此 Rectangle 的大小。Component.getSize(),
setSize(Dimension),
setSize(int, int)public void setSize(Dimension d)
Rectangle 的大小,以匹配指定的 Dimension。
包含此方法是出于完整性考虑,它与 Component 的 setSize 方法相似。
d - Dimension 对象的新大小Component.setSize(java.awt.Dimension),
getSize()
public void setSize(int width,
int height)
Rectangle 的大小设置为指定的宽度和高度。
包含此方法是出于完整性考虑,它与 Component 的 setSize 方法相似。
width - 此 Rectangle 的新宽度height - 此 Rectangle 的新高度Component.setSize(int, int),
getSize()
@Deprecated
public void resize(int width,
int height)
setSize(int, int) 取代。
Rectangle 的大小设置为指定的宽度和高度。
width - 此 Rectangle 的新宽度height - 此 Rectangle 的新高度public boolean contains(Point p)
Rectangle 是否包含指定的 Point。
p - 要测试的 Point
Point(x,y)在此 Rectangle 中,则返回 true;否则返回 false。
public boolean contains(int x,
int y)
Rectangle 是否包含指定位置的点(x,y)。
x - 指定的 x 坐标y - 指定的 y 坐标
Rectangle 中,则返回 true;否则返回 false。public boolean contains(Rectangle r)
Rectangle 是否完整地包含指定的 Rectangle。
r - 指定的 Rectangle
Rectangle 完整地包含在此 Rectangle 中,则返回 true;否则返回 false
public boolean contains(int X,
int Y,
int W,
int H)
Rectangle 是否完整地包含指定位置(X,Y)上具有指定尺寸(W,H)的 Rectangle。
X - 指定的 x 坐标Y - 指定的 y 坐标W - Rectangle 的宽度H - Rectangle 的高度
Rectangle 完全包含在此 Rectangle 中,则返回 true;否则返回 false。
@Deprecated
public boolean inside(int X,
int Y)
contains(int, int) 取代。
Rectangle 是否包含指定位置的点(X,Y)。
X - 指定的 x 坐标Y - 指定的 y 坐标
Rectangle 中,则返回 true,否则返回 false。public boolean intersects(Rectangle r)
Rectangle 是否与指定 Rectangle 相交。如果两个矩形的交集为非空,则它们是相交的。
r - 指定的 Rectangle
Rectangle 与此 Rectangle 相交,则返回 true;否则返回 false。public Rectangle intersection(Rectangle r)
Rectangle 与指定 Rectangle 的交集。返回一个新的 Rectangle,它表示两个矩形的交集。如果两个矩形没有相交,则结果将是一个空矩形。
r - 指定的 Rectangle
Rectangle 和此 Rectangle 的最大的 Rectangle;如果两个矩形没有相交,则返回一个空矩形。public Rectangle union(Rectangle r)
Rectangle 与指定 Rectangle 的并集。返回一个表示两个矩形的并集的新 Rectangle
r - 指定的 Rectangle
Rectangle 和此 Rectangle 的最小的 Rectangle。
public void add(int newx,
int newy)
Rectangle,这个点由整数参数 newx 和 newy 指定。所得到的 Rectangle 是包含原始 Rectangle 和指定点的最小的 Rectangle。
在添加一个点后,调用将添加的点用作参数的 contains 方法不一定返回 true。对于 Rectangle 的右边和底部边界线上的点,contains 方法不返回 true。所以,如果添加的点落在放大的 Rectangle 的右边和底部边界线上,则 contains 将针对该点返回 false。
newx - 新点的 x 坐标newy - 新点的 y 坐标public void add(Point pt)
Point 添加到此 Rectangle 中。所得到的 Rectangle 是包含原始 Rectangle 和指定 Point 的最小的 Rectangle。
在添加一个 Point 后,调用将添加的 Point 用作参数的 contains 方法不一定返回 true。对于 Rectangle 的右边和底部边界线上的点,contains 方法不返回 true。所以,如果添加的 Point 落在放大的 Rectangle 的右边和底部边界线上,则 contains 将针对该 Point 返回 false。
pt - 添加到此 Rectangle 中的新 Pointpublic void add(Rectangle r)
Rectangle 添加到此 Rectangle 中。所得到的 Rectangle 是两个矩形的并集。
r - 指定的 Rectangle
public void grow(int h,
int v)
Rectangle 的大小。
此方法能修改 Rectangle,使它左边和右边都增加 h 单位,顶部和底部都增加 v 单位。
新的 Rectangle 的左上角是(x - h,y - v),宽度是 width + 2h,高度是 height + 2v。
如果为 h 和 v 提供负值,则 Rectangle 的大小也将相应地缩小。grow 方法不检查所得到的 width 和 height 值是否为非负值。
h - 水平扩展v - 垂直扩展public boolean isEmpty()
Rectangle 是否为空。如果宽度或高度小于等于零,则 Rectangle 为空。
RectangularShape 中的 isEmptyRectangle 为空,则返回 true;否则返回 false。
public int outcode(double x,
double y)
Rectangle 的位置。此方法计算了适当掩码值的二进制 OR,这些值针对此 Rectangle 的每个边指示了指定坐标是否在此 Rectangle 的其余边缘的同一侧。
Rectangle2D 中的 outcodex - 指定的 x 坐标y - 指定的 y 坐标
Rectangle2D.OUT_LEFT,
Rectangle2D.OUT_TOP,
Rectangle2D.OUT_RIGHT,
Rectangle2D.OUT_BOTTOMpublic Rectangle2D createIntersection(Rectangle2D r)
Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的交集。
Rectangle2D 中的 createIntersectionr - 与此 Rectangle 相交的 Rectangle2D
Rectangle2D 和此 Rectangle 的最大的 Rectangle2D。public Rectangle2D createUnion(Rectangle2D r)
Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的并集。
Rectangle2D 中的 createUnionr - 与此 Rectangle 合并的 Rectangle2D
Rectangle2D 和此 Rectangle 的最小的 Rectangle2D。public boolean equals(Object obj)
当且仅当参数不是 null,而是一个与此 Rectangle 具有相同的左上角、宽度和高度的 Rectangle 对象时,结果才为 true。
Rectangle2D 中的 equalsobj - 将与此 Rectangle 进行比较的 Object
true;否则返回 false。Object.hashCode(),
Hashtablepublic String toString()
Rectangle 及其值的 String。
Object 中的 toStringRectangle 对象的坐标和大小值的 String。
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。