public class Rectangle extends Rectangle2D implements Shape, Serializable
Rectangle
指定一个坐标空间是由
Rectangle
对象的左上点
(x,y)
在坐标空间,封闭区域的宽度和高度。
一个Rectangle
对象的width
和height
是public
领域。该构造函数创建一个Rectangle
,并且可以修改一个方法,不防设置宽度或高度的负价值。
A Rectangle
whose width or height is exactly zero has location along those axes with zero dimension, but is otherwise considered empty. The isEmpty()
方法将返回true,这样的Rectangle
。检验方法如果空Rectangle
包含或相交的点或矩形永远如果维数为零返回false。这样的Rectangle
与点或矩形相结合的方法将包括位置的Rectangle
上轴的结果如果add(Point)
方法被称为。
方法只影响到一个Rectangle
位置将其位置,不管它是否具有负的或零维沿轴。
注意,默认的无参数构造函数将尺寸0x0
因此是空的了Rectangle
。这Rectangle
仍有一个位置,将有助于(0,0)
位置的联盟和添加操作。代码试图积累一套点应初步构建了Rectangle
具有负的宽度和高度也应该使用集合中的第一点构建Rectangle
界限。例如:
Rectangle bounds = new Rectangle(0, 0, -1, -1);
for (int i = 0; i < points.length; i++) {
bounds.add(points[i]);
}
或如果我们知道点阵列包含至少一点:
Rectangle bounds = new Rectangle(points[0]);
for (int i = 1; i < points.length; i++) {
bounds.add(points[i]);
}
这个类使用32位整数来存储它的位置和尺寸。频繁操作可能会产生超过32位整数的范围的结果。该方法将计算他们的结果的一种方法,以避免任何的32位溢出的中间结果,然后选择最好的表示来存储到32位字段,保持位置和尺寸的最终结果。结果的位置将被存储到x
和y
田野的真实结果夹到最近的32位值。的值存储到width
和height
维度字段将被选为32位值,包括真实的结果尽可能最大的部分。一般来说,这意味着该尺寸将被修剪独立的范围内的32位整数,但如果位置必须被移动到它的对存储到它的对32位字段,然后将调整的尺寸相对于位置的“最佳代表性”。如果真的造成了负面的维度,因此不存在沿一个或两个轴,存储规模将在这些轴是负数。如果真正的结果有一个位置,可以表示在32位整数的范围内,但在一个或两个轴的零维,然后存储的尺寸将在这些轴为零。
Rectangle2D.Double, Rectangle2D.Float
Modifier and Type | Field and Description |
---|---|
int |
height
Rectangle 的高度。
|
int |
width
该
Rectangle 宽度。
|
int |
x
对
Rectangle 左上角的x坐标。
|
int |
y
对
Rectangle 左上角的Y坐标。
|
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
Constructor and Description |
---|
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(Rectangle r)
构建了一种新的
Rectangle ,初始化为指定的值相匹配
Rectangle 。
|
Modifier and Type | Method and Description |
---|---|
void |
add(int newx, int newy)
补充一点,由整数参数
newx,newy 指定本
Rectangle 界限。
|
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) 与指定尺寸的
Rectangle
(W,H) 。
|
boolean |
contains(Point p)
检查是否包含指定的
Point
Rectangle 。
|
boolean |
contains(Rectangle r)
检查是否
Rectangle 完全包含指定的
Rectangle 。
|
Rectangle2D |
createIntersection(Rectangle2D r)
返回一个新的
Rectangle2D 对象表示与指定的
Rectangle2D 这
Rectangle2D 路口。
|
Rectangle2D |
createUnion(Rectangle2D r)
返回一个新的
Rectangle2D 表示这
Rectangle2D 与指定的
Rectangle2D 联盟。
|
boolean |
equals(Object obj)
检查两个矩形是否相等。
|
Rectangle |
getBounds()
得到这
Rectangle 包围
Rectangle 。
|
Rectangle2D |
getBounds2D()
返回一个高的精度和更精确的包围盒的
Shape 比
getBounds 方法。
|
double |
getHeight()
返回包围
Rectangle 在
double 精度高。
|
Point |
getLocation()
返回该
Rectangle 位置。
|
Dimension |
getSize()
得到这
Rectangle 大小,返回到
Dimension 代表。
|
double |
getWidth()
返回包围
Rectangle 在
double 精度的宽度。
|
double |
getX()
返回包围
Rectangle 在
double 精密的X坐标。
|
double |
getY()
返回包围
Rectangle 在
double 精密坐标。
|
void |
grow(int h, int v)
调整
Rectangle 横向和纵向。
|
boolean |
inside(int X, int Y)
过时的。
作为JDK 1.1版本,取而代之的
contains(int, int) 。
|
Rectangle |
intersection(Rectangle r)
计算这
Rectangle 路口与指定的
Rectangle 。
|
boolean |
intersects(Rectangle r)
确定是否这
Rectangle 和指定的
Rectangle 相交。
|
boolean |
isEmpty()
确定
RectangularShape 是空的。
|
void |
move(int x, int y)
过时的。
作为JDK 1.1版本,取而代之的
setLocation(int, int) 。
|
int |
outcode(double x, double y)
确定指定的坐标是相对于这个
Rectangle2D 。
|
void |
reshape(int x, int y, int width, int height)
过时的。
作为JDK 1.1版本,取而代之的
setBounds(int, int, int, int) 。
|
void |
resize(int width, int height)
过时的。
作为JDK 1.1版本,取而代之的
setSize(int, int) 。
|
void |
setBounds(int x, int y, int width, int height)
设置指定的
x ,
y ,
width 这
Rectangle 包围
Rectangle ,和
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)
设置要符合指定的
Dimension 这
Rectangle 大小。
|
void |
setSize(int width, int height)
设置指定的宽度和高度,这
Rectangle 大小。
|
String |
toString()
返回一个
String 代表这个
Rectangle 及其价值。
|
void |
translate(int dx, int dy)
翻译这
Rectangle 指示的距离,沿X坐标轴的右侧,向下沿Y坐标轴。
|
Rectangle |
union(Rectangle r)
计算这
Rectangle 工会与指定的
Rectangle 。
|
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
finalize, getClass, notify, notifyAll, wait, wait, wait
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)
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()
Rectangle
在
double
精密的X坐标。
getX
方法重写,继承类
RectangularShape
Rectangle
X坐标。
public double getY()
Rectangle
在
double
精密坐标。
getY
方法重写,继承类
RectangularShape
Rectangle
Y坐标。
public double getWidth()
Rectangle
在
double
精度的宽度。
getWidth
方法重写,继承类
RectangularShape
Rectangle
宽度的边界。
public double getHeight()
Rectangle
在
double
精度高。
getHeight
方法重写,继承类
RectangularShape
Rectangle
高度。
public Rectangle getBounds()
getBounds
接口
Shape
getBounds
方法重写,继承类
RectangularShape
Rectangle
,等于包围
Rectangle
这
Rectangle
。
Component.getBounds()
,
setBounds(Rectangle)
,
setBounds(int, int, int, int)
public Rectangle2D getBounds2D()
Shape
比
getBounds
方法。需要注意的是不能保证返回的
Rectangle2D
是最小包围盒包围
Shape
,只有
Shape
完全在于在显示
Rectangle2D
。包围盒返回此方法通常是更严格的比
getBounds
返回的方法,永远不会失败由于溢出的问题由于返回值可以使用双精度值存储维度的
Rectangle2D
实例。
请注意, definition of insideness可导致的情况下,点上的shape
定义轮廓可能不被视为包含在返回的bounds
对象,但只有在这些点的情况下,也不被认为是包含在原始的shape
。
如果一个point
在shape
根据contains(point)
方法,那么它必须在返回的Rectangle2D
界根据的bounds
的contains(point)
方法对象。明确地:
shape.contains(p)
需要bounds.contains(p)
如果一个point
是不是在shape
,那么它可能仍然包含在bounds
对象:
bounds.contains(p)
并不意味着shape.contains(p)
getBounds2D
接口
Shape
getBounds2D
方法重写,继承类
Rectangle2D
Rectangle2D
包围盒的
Shape
实例。
Shape.getBounds()
public void setBounds(Rectangle r)
Rectangle
这
Rectangle
Rectangle
该方法包括完整性、平行Component
的setBounds
方法。
r
-指定
Rectangle
getBounds()
,
Component.setBounds(java.awt.Rectangle)
public void setBounds(int x, int y, int width, int height)
x
,
y
,
width
这
Rectangle
包围
Rectangle
,和
height
。
该方法包括完整性、平行Component
的setBounds
方法。
x
-新的X坐标为本
Rectangle
左上角
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
。如果该参数指定一个超过整数的最大范围
Rectangle
,结果将是指定的
Rectangle
相交的最大整数界最好的表示。
setRect
方法重写,继承类
Rectangle2D
x
-在指定矩形左上角的x坐标
y
-在指定矩形左上角的Y坐标
width
-指定矩形的宽度
height
-指定矩形的新高度
@Deprecated public void reshape(int x, int y, int width, int height)
setBounds(int, int, int, int)
。
x
,
y
,
width
这
Rectangle
包围
Rectangle
,和
height
。
x
-新的X坐标为本
Rectangle
左上角
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
-
Point
这
Rectangle
指定新位置
Component.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 dx, int dy)
Rectangle
指示的距离,沿X坐标轴的右侧,向下沿Y坐标轴。
dx
-移动
Rectangle
沿X轴的距离
dy
-沿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)
Dimension
这
Rectangle
大小。
该方法包括完整性、平行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)
Point
Rectangle
。
p
-
Point
测试
true
如果指定
Point
是这里面
Rectangle
;
false
否则。
public boolean contains(int x, int y)
Rectangle
包含指向指定的位置
(x,y)
。
x
-指定的X坐标
y
-指定的y坐标
true
如果点
(x,y)
是这里面
Rectangle
;
false
否则。
public boolean contains(Rectangle r)
Rectangle
完全包含指定的
Rectangle
。
r
-指定
Rectangle
true
如果
Rectangle
是完全包含在这个
Rectangle
;
false
否则
public boolean contains(int X, int Y, int W, int H)
Rectangle
完全包含在指定的位置
(X,Y)
与指定尺寸的
Rectangle
(W,H)
。
X
-指定的X坐标
Y
-指定的y坐标
W
的
Rectangle
宽度
H
的
Rectangle
高度
true
(X, Y, W, H)
Rectangle
完全封闭在这个
Rectangle
;
false
否则。
@Deprecated public boolean inside(int X, int Y)
contains(int, int)
。
Rectangle
包含指向指定的位置
(X,Y)
。
X
-指定的X坐标
Y
-指定的y坐标
true
如果点
(X,Y)
是这里面
Rectangle
;
false
否则。
public boolean intersects(Rectangle r)
Rectangle
和指定的
Rectangle
相交。如果他们两个矩形相交的交集非空。
r
-指定
Rectangle
true
如果指定
Rectangle
这
Rectangle
相交;
false
否则。
public Rectangle intersection(Rectangle r)
Rectangle
路口与指定的
Rectangle
。返回一个新的
Rectangle
表示两个矩形的交集。如果两个矩形不相交,结果将是一个空矩形。
r
-指定
Rectangle
Rectangle
在这
Rectangle
中最大的
Rectangle
;或者如果矩形不相交,一个空的矩形。
public Rectangle union(Rectangle r)
Rectangle
工会与指定的
Rectangle
。返回一个新的
Rectangle
表示两个矩形的联盟。
如果Rectangle
有任何尺寸小于零的non-existant矩形规则的应用。如果只有一个尺寸小于零,那么结果将是其他的副本Rectangle
。如果两个尺寸小于零,那么结果将至少有一个尺寸小于零。
如果得到的Rectangle
有尺寸太大被表示为一个int
,结果会有Integer.MAX_VALUE
沿着维度维度。
r
-指定
Rectangle
Rectangle
包含指定的
Rectangle
这
Rectangle
。
public void add(int newx, int newy)
newx,newy
指定本
Rectangle
界限。
如果这Rectangle
有任何尺寸小于零,为non-existant矩形规则的应用。在这种情况下,这Rectangle
新范围将有一个位置等于指定的坐标和宽度和高度等于零。
添加一个点后,一个叫contains
加点作为参数不一定回true
。的contains
方法不返回对Rectangle
右边或底部边缘点true
。因此,如果说点落在扩Rectangle
右边或底部边缘,contains
返回false
那点。如果指定的点必须包含在新的Rectangle
,一个1x1的矩形应反而增加:
r.add(newx,期货交易所,1,1);
newx
-新的点的x坐标
newy
-新的点的Y坐标
public void add(Point pt)
Point
到这
Rectangle
界限。
如果这Rectangle
有任何尺寸小于零,为non-existant矩形规则的应用。在这种情况下,这Rectangle
新范围将有一个位置等于指定的Point
和宽度和高度等于零的坐标。
添加一个Point
后,打电话给contains
加Point
作为参数不一定回true
。的contains
方法不返回对Rectangle
右边或底部边缘点true
。因此如果说Point
落在扩大Rectangle
右边或底部边缘,contains
返回false
,Point
。如果指定的点必须包含在新的Rectangle
,一个1x1的矩形应反而增加:
r.add(PT,PT X,Y,1,1。);
pt
-添加到这个新的
Point
Rectangle
public void add(Rectangle r)
Rectangle
这
Rectangle
。由此产生的
Rectangle
是两个矩形的联盟。
如果Rectangle
有任何尺寸小于0,结果会有其他Rectangle
尺寸。如果Rectangle
s至少有一个尺寸小于0,结果将至少有一个尺寸小于0。
如果有一个或两个Rectangle
尺寸等于0,结果沿着这些轴用0个维度将相当于通过加入相应的坐标轴的矩形沿结果结果,类似的add(Point)
方法的操作,但没有进一步的尺寸之外。
如果得到的Rectangle
有尺寸太大被表示为一个int
,结果会有Integer.MAX_VALUE
沿着维度维度。
r
-指定
Rectangle
public void grow(int h, int v)
Rectangle
横向和纵向。
此方法修改Rectangle
这样h
单位左右两边均较大,和v
单位大的顶部和底部。
新Rectangle
已经(x - h, y - v)
为左上角,宽度和高度(height + 2v)
(width + 2h)
。
如果负面的价值是h
和v
提供的Rectangle
尺寸相应减小。的grow
方法将检查整数溢出和下溢,但不检查是否产生的价值和height
width
增长由负非负或缩小非否定之否定。
h
的横向扩展
v
-垂直扩展
public boolean isEmpty()
RectangularShape
是空的。当
RectangularShape
是空的,它包含的任何地区。
isEmpty
方法重写,继承类
RectangularShape
true
如果
RectangularShape
是空的;
false
否则。
public int outcode(double x, double y)
Rectangle2D
。这种方法计算一个二进制或合适的掩码值指示,为本
Rectangle2D
每边,是否指定的坐标是在边缘的同侧,这
Rectangle2D
休息。
outcode
方法重写,继承类
Rectangle2D
x
-指定的X坐标
y
-指定的y坐标
Rectangle2D.OUT_LEFT
,
Rectangle2D.OUT_TOP
,
Rectangle2D.OUT_RIGHT
,
Rectangle2D.OUT_BOTTOM
public Rectangle2D createIntersection(Rectangle2D r)
Rectangle2D
对象表示与指定的
Rectangle2D
这
Rectangle2D
路口。
createIntersection
方法重写,继承类
Rectangle2D
r
-
Rectangle2D
是相交的这
Rectangle2D
Rectangle2D
在这
Rectangle2D
中最大的
Rectangle2D
。
public Rectangle2D createUnion(Rectangle2D r)
Rectangle2D
表示这
Rectangle2D
与指定的
Rectangle2D
联盟。
createUnion
方法重写,继承类
Rectangle2D
r
-
Rectangle2D
要结合本
Rectangle2D
Rectangle2D
包含指定的
Rectangle2D
这
Rectangle2D
。
public boolean equals(Object obj)
其结果是true
如果只有参数不null
是Rectangle
对象具有相同的左上角,宽度和高度,因为这Rectangle
。
equals
方法重写,继承类
Rectangle2D
obj
-
Object
与这个
Rectangle
比较
true
如果对象是平等的;
false
否则。
Object.hashCode()
,
HashMap
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.