Rectangle クラス
- [内容]
- 矩形領域を表すクラスです.座標の値は整数ですが,double の値を持つ Rectangle2D というクラスも存在します.
- [主な変数]
- public int height
- 矩形領域の高さ
- public int width
- 矩形領域の幅
- public int x
- 矩形領域の左上角の x 座標
- public int y
- 矩形領域の左上角の y 座標
- [コンストラクタ]
- public Rectangle()
- public Rectangle(Dimension d)
- public Rectangle(int width, int height)
- public Rectangle(int x, int y, int width, int height)
- public Rectangle(Point p)
- public Rectangle(Point p, Dimension d)
- public Rectangle(Rectangle r)
- 指定された位置と大きさを持つ Rectangle オブジェクトを生成する.位置が指定されないと原点 (0, 0),また,大きさが指定されないと 0 となる.
- [主なメソッド]
- public void add(int newx, int newy)
- public void add(Point pt)
- 矩形に点を加える.結果として,最初の矩形と点を含んだ最小の矩形となる.
- public void add(Rectangle r)
- 矩形に指定された矩形を加える.結果として,2 つの矩形を含んだ最小の矩形となる.
- public boolean contains(int x, int y)
- public boolean contains(Point p)
- public boolean contains(int X, int Y, int W, int H)
- public boolean contains(Rectangle r)
- 指定された点(最初の 2 つ),または,矩形(最後の 2 つ)を含んでいるか否かを返す
- public Rectangle2D createIntersection(Rectangle2D r)
- 指定された矩形との共通部分からなる Rectangle2D オブジェクトを返す
- public Rectangle2D createUnion(Rectangle2D r)
- 指定された矩形を含む最小の Rectangle2D オブジェクトを返す
- public void grow(int h, int v)
- 矩形の大きさを変える.結果として,座標は (x-h, y-v),幅及び高さは 2h および 2v となる.
- public Rectangle intersection(Rectangle r)
- 指定された矩形との共通部分からなる Rectangle オブジェクトを返す
- public boolean intersects(Rectangle r)
- 指定された矩形との共通部分があるか否かを返す
- public void setLocation(int x, int y)
- public void setLocation(Point p)
- 矩形の位置を変える
- public void setSize(Dimension d)
- public void setSize(int width, int height)
- 矩形の大きさを変える
- public void translate(int dx, int dy)
- 矩形の位置を dx 及び dy だけ平行移動する
- public Rectangle union(Rectangle r)
- 指定された矩形を含む最小の Rectangle オブジェクトを返す
- [使用例]
- プログラム例は,Rectangle クラスの各メソッド等の使用例です.
- [参照]
- Point, Polygon