所有类


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 对象的左上顶点的坐标(xy)、宽度和高度可以定义这个区域。

Rectangle 对象的 widthheightpublic 字段。创建 Rectangle 的构造方法,以及可以修改该对象的方法,都不会禁止将 width 或 height 设置为负值。

如果 Rectangle 的 width 或 height 为负值,则认为 Rectangle 为空。如果 Rectangle 为空,则 isEmpty 方法将返回 true。空 Rectangle 中不包含任何点,或者说其内部没有任何点。但是,widthheight 的值仍然有效。空 Rectangle 在坐标空间中仍有一个位置,改变其大小或位置的方法仍然有效。如果任何参与操作的 Rectangle 对象有一个负的 widthheight,则对过个 Rectangle 进行操作的方法的行为是不确定的。这些方法包括 intersectsintersectionunion

从以下版本开始:
JDK1.0
另请参见:
序列化表格

嵌套类摘要
 
从类 java.awt.geom.Rectangle2D 继承的嵌套类/接口
Rectangle2D.Double, Rectangle2D.Float
 
字段摘要
 intheight
          Rectangle 的高度。
 intwidth
          Rectangle 的宽度。
 intx
          Rectanglex 坐标。
 inty
          Rectangley 坐标。
 
从类 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,其左上角被指定为(xy),而其宽度和高度由同名称的参数指定。
Rectangle(Point p)
          构造一个新的 Rectangle,其左上顶点是指定的 Point,并且其宽度和高度均为零。
Rectangle(Point p, Dimension d)
          构造一个新的 Rectangle,其左上角由 Point 参数指定,其宽度和高度由 Dimension 参数指定。
Rectangle(Rectangle r)
          构造一个新的 Rectangle,并将其初始化,以匹配指定 Rectangle 的值。
 
方法摘要
 voidadd(int newx, int newy)
          将一个点添加到此 Rectangle,这个点由整数参数 newxnewy 指定。
 voidadd(Point pt)
          将指定的 Point 添加到此 Rectangle 中。
 voidadd(Rectangle r)
          将一个 Rectangle 添加到此 Rectangle 中。
 booleancontains(int x, int y)
          检查此 Rectangle 是否包含指定位置的点(xy)。
 booleancontains(int X, int Y, int W, int H)
          检查此 Rectangle 是否完整地包含指定位置(XY)上具有指定尺寸(WH)的 Rectangle
 booleancontains(Point p)
          检查此 Rectangle 是否包含指定的 Point
 booleancontains(Rectangle r)
          检查此 Rectangle 是否完整地包含指定的 Rectangle
 Rectangle2DcreateIntersection(Rectangle2D r)
          返回一个新的 Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的交集。
 Rectangle2DcreateUnion(Rectangle2D r)
          返回一个新的 Rectangle2D 对象,它表示此 Rectangle 与指定 Rectangle2D 的并集。
 booleanequals(Object obj)
          检查两个矩形是否相等。
 RectanglegetBounds()
          获得此 Rectangle 的边界 Rectangle
 Rectangle2DgetBounds2D()
          返回此 rectangle 的高精度边界框。
 doublegetHeight()
          以 double 精度形式返回边界 Rectangle 的高度。
 PointgetLocation()
          返回此 Rectangle 的位置。
 DimensiongetSize()
          获得此 Rectangle 的大小,用返回的 Dimension 表示。
 doublegetWidth()
          以 double 精度形式返回边界 Rectangle 的宽度。
 doublegetX()
          以 double 精度形式返回边界 Rectangle 的 X 坐标。
 doublegetY()
          以 double 精度形式返回边界 Rectangle 的 Y 坐标。
 voidgrow(int h, int v)
          在水平方向和垂直方向上重新设置 Rectangle 的大小。
 booleaninside(int X, int Y)
          已过时。 从 JDK version 1.1 开始,由 contains(int, int) 取代。
 Rectangleintersection(Rectangle r)
          计算此 Rectangle 与指定 Rectangle 的交集。
 booleanintersects(Rectangle r)
          确定此 Rectangle 是否与指定 Rectangle 相交。
 booleanisEmpty()
          确定此 Rectangle 是否为空。
 voidmove(int x, int y)
          已过时。 从 JDK version 1.1 开始,由 setLocation(int, int) 取代。
 intoutcode(double x, double y)
          确定指定坐标相对于此 Rectangle 的位置。
 voidreshape(int x, int y, int width, int height)
          已过时。 从 JDK version 1.1 开始,由 setBounds(int, int, int, int) 取代。
 voidresize(int width, int height)
          已过时。 从 JDK version 1.1 开始,由 setSize(int, int) 取代。
 voidsetBounds(int x, int y, int width, int height)
          将此 Rectangle 的边界 Rectangle 设置为指定的 xywidthheight
 voidsetBounds(Rectangle r)
          设置此 Rectangle 的边界 Rectangle,以匹配指定的 Rectangle
 voidsetLocation(int x, int y)
          将此 Rectangle 移动到指定位置。
 voidsetLocation(Point p)
          将此 Rectangle 移动到指定位置。
 voidsetRect(double x, double y, double width, double height)
          将此 Rectangle 的边界设置为指定的 xywidthheight
 voidsetSize(Dimension d)
          设置此 Rectangle 的大小,以匹配指定的 Dimension
 voidsetSize(int width, int height)
          将此 Rectangle 的大小设置为指定的宽度和高度。
 StringtoString()
          返回表示此 Rectangle 及其值的 String
 voidtranslate(int x, int y)
          将此 Rectangle 沿 x 坐标轴向右,沿 y 坐标轴向下移动指定距离。
 Rectangleunion(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
Rectanglex 坐标。

另请参见:
setLocation(int, int), getLocation()

y

public int y
Rectangley 坐标。

另请参见:
setLocation(int, int), getLocation()

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,其左上角被指定为(xy),而其宽度和高度由同名称的参数指定。

参数:
x - 指定的 x 坐标
y - 指定的 y 坐标
width - Rectangle 的宽度
height - Rectangle 的高度

Rectangle

public Rectangle(int width,
                 int height)
构造一个新的 Rectangle,其左上角的坐标为(0,0),而其宽度和高度由同名的参数指定。

参数:
width - Rectangle 的宽度
height - Rectangle 的高度