Rectangle
A Rectangle object's width and height are public fields. The constructors that create a Rectangle, and the methods that can modify one, do not prevent setting a negative value for width or height. A Rectangle whose width or height is exactly zero has location along those axes with zero dimension, but is otherwise considered empty. The isEmpty() method will return true for such a Rectangle. Methods which test if an empty Rectangle contains or intersects a point or rectangle will always return false if either dimension is zero. Methods which combine such a Rectangle with a point or rectangle will include the location of the Rectangle on that axis in the result as if the add(Point) method were being called. A Rectangle whose width or height is negative has neither location nor dimension along those axes with negative dimensions. Such a Rectangle is treated as non-existant along those axes. Such a Rectangle is also empty with respect to containment calculations and methods which test if it contains or intersects a point or rectangle will always return false. Methods which combine such a Rectangle with a point or rectangle will ignore the Rectangle entirely in generating the result. If two Rectangle objects are combined and each has a negative dimension, the result will have at least one negative dimension. Methods which affect only the location of a Rectangle will operate on its location regardless of whether or not it has a negative or zero dimension along either axis. Note that a Rectangle constructed with the default no-argument constructor will have dimensions of 0x0 and therefore be empty. That Rectangle will still have a location of (0,0) and will contribute that location to the union and add operations. Code attempting to accumulate the bounds of a set of points should therefore initially construct the Rectangle with a specifically negative width and height or it should use the first point in the set to construct the Rectangle. For example: Rectangle bounds = new Rectangle(0, 0, -1, -1); for (int i = 0; i Nested Class SummaryNested classes/interfaces inherited from class java.awt.geom.Rectangle2DRectangle2D.Double, Rectangle2D.FloatField SummaryFields Modifier and TypeField and DescriptionintheightThe height of the Rectangle.intwidthThe width of the Rectangle.intxThe X coordinate of the upper-left corner of the Rectangle.intyThe Y coordinate of the upper-left corner of the Rectangle.Fields inherited from class java.awt.geom.Rectangle2DOUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOPConstructor SummaryConstructors Constructor and DescriptionRectangle()Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.Rectangle(Dimension d)Constructs a new Rectangle whose top left corner is (0, 0) and whose width and height are specified by the Dimension argument.Rectangle(int width, int height)Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.Rectangle(int x, int y, int width, int height)Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.Rectangle(Point p)Constructs a new Rectangle whose upper-left corner is the specified Point, and whose width and height are both zero.Rectangle(Point p, Dimension d)Constructs a new Rectangle whose upper-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.Rectangle(Rectangle r)Constructs a new Rectangle, initialized to match the values of the specified Rectangle.Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and TypeMethod and Descriptionvoidadd(int newx, int newy)Adds a point, specified by the integer arguments newx,newy to the bounds of this Rectangle.voidadd(Point pt)Adds the specified Point to the bounds of this Rectangle.voidadd(Rectangle r)Adds a Rectangle to this Rectangle.booleancontains(int x, int y)Checks whether or not this Rectangle contains the point at the specified location (x,y).booleancontains(int X, int Y, int W, int H)Checks whether this Rectangle entirely contains the Rectangle at the specified location (X,Y) with the specified dimensions (W,H).booleancontains(Point p)Checks whether or not this Rectangle contains the specified Point.booleancontains(Rectangle r)Checks whether or not this Rectangle entirely contains the specified Rectangle.Rectangle2DcreateIntersection(Rectangle2D r)Returns a new Rectangle2D object representing the intersection of this Rectangle2D with the specified Rectangle2D.Rectangle2DcreateUnion(Rectangle2D r)Returns a new Rectangle2D object representing the union of this Rectangle2D with the specified Rectangle2D.booleanequals(Object obj)Checks whether two rectangles are equal.RectanglegetBounds()Gets the bounding Rectangle of this Rectangle.Rectangle2DgetBounds2D()Returns a high precision and more accurate bounding box of the Shape than the getBounds method.doublegetHeight()Returns the height of the bounding Rectangle in double precision.PointgetLocation()Returns the location of this Rectangle.DimensiongetSize()Gets the size of this Rectangle, represented by the returned Dimension.doublegetWidth()Returns the width of the bounding Rectangle in double precision.doublegetX()Returns the X coordinate of the bounding Rectangle in double precision.doublegetY()Returns the Y coordinate of the bounding Rectangle in double precision.voidgrow(int h, int v)Resizes the Rectangle both horizontally and vertically.booleaninside(int X, int Y)Deprecated. As of JDK version 1.1, replaced by contains(int, int).Rectangleintersection(Rectangle r)Computes the intersection of this Rectangle with the specified Rectangle.booleanintersects(Rectangle r)Determines whether or not this Rectangle and the specified Rectangle intersect.booleanisEmpty()Determines whether the RectangularShape is empty.voidmove(int x, int y)Deprecated. As of JDK version 1.1, replaced by setLocation(int, int).intoutcode(double x, double y)Determines where the specified coordinates lie with respect to this Rectangle2D.voidreshape(int x, int y, int width, int height)Deprecated. As of JDK version 1.1, replaced by setBounds(int, int, int, int).voidresize(int width, int height)Deprecated. As of JDK version 1.1, replaced by setSize(int, int).voidsetBounds(int x, int y, int width, int height)Sets the bounding Rectangle of this Rectangle to the specified x, y, width, and height.voidsetBounds(Rectangle r)Sets the bounding Rectangle of this Rectangle to match the specified Rectangle.voidsetLocation(int x, int y)Moves this Rectangle to the specified location.voidsetLocation(Point p)Moves this Rectangle to the specified location.voidsetRect(double x, double y, double width, double height)Sets the bounds of this Rectangle to the integer bounds which encompass the specified x, y, width, and height.voidsetSize(Dimension d)Sets the size of this Rectangle to match the specified Dimension.voidsetSize(int width, int height)Sets the size of this Rectangle to the specified width and height.StringtoString()Returns a String representing this Rectangle and its values.voidtranslate(int dx, int dy)Translates this Rectangle the indicated distance, to the right along the X coordinate axis, and downward along the Y coordinate axis.Rectangleunion(Rectangle r)Computes the union of this Rectangle with the specified Rectangle.Methods inherited from class java.awt.geom.Rectangle2Dadd, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, unionMethods inherited from class java.awt.geom.RectangularShapeclone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonalMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.awt.Shapecontains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersectsField Detailxpublic int xThe X coordinate of the upper-left corner of the Rectangle.Since:1.0See Also:setLocation(int, int), getLocation()ypublic int yThe Y coordinate of the upper-left corner of the Rectangle.Since:1.0See Also:setLocation(int, int), getLocation()widthpublic int widthThe width of the Rectangle.Since:1.0See Also:setSize(int, int), getSize()heightpublic int heightThe height of the Rectangle.Since:1.0See Also:setSize(int, int), getSize()Constructor DetailRectanglepublic Rectangle()Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.Rectanglepublic Rectangle(Rectangle r)Constructs a new Rectangle, initialized to match the values of the specified Rectangle.Parameters:r - the Rectangle from which to copy initial values to a newly constructed RectangleSince:1.1Rectanglepublic Rectangle(int x, int y, int width, int height)Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.Parameters:x - the specified X coordinatey - the specified Y coordinatewidth - the width of the Rectangleheight - the height of the RectangleSince:1.0Rectanglepublic Rectangle(int width, int height)Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are specified by the arguments of the same name.Parameters:width - the width of the Rectangleheight - the height of the RectangleRectanglepublic Rectangle(Point p, Dimension d)Constructs a new Rectangle whose upper-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.Parameters:p - a Point that is the upper-left corner of the Rectangled - a Dimension, representing the width and height of the RectangleRectanglepublic Rectangle(Point p)Constructs a new Rectangle whose upper-left corner is the specified Point, and whose width and height are both zero.Parameters:p - a Point that is the top left corner of the RectangleRectanglepublic Rectangle(Dimension d)Constructs a new Rectangle whose top left corner is (0, 0) and whose width and height are specified by the Dimension argument.Parameters:d - a Dimension, specifying width and heightMethod DetailgetXpublic double getX()Returns the X coordinate of the bounding Rectangle in double precision.Specified by:getX in class RectangularShapeReturns:the X coordinate of the bounding Rectangle.getYpublic double getY()Returns the Y coordinate of the bounding Rectangle in double precision.Specified by:getY in class RectangularShapeReturns:the Y coordinate of the bounding Rectangle.getWidthpublic double getWidth()Returns the width of the bounding Rectangle in double precision.Specified by:getWidth in class RectangularShapeReturns:the width of the bounding Rectangle.getHeightpublic double getHeight()Returns the height of the bounding Rectangle in double precision.Specified by:getHeight in class RectangularShapeReturns:the height of the bounding Rectangle.getBoundspublic Rectangle getBounds()Gets the bounding Rectangle of this Rectangle. This method is included for completeness, to parallel the getBounds method of Component.Specified by:getBounds in interface ShapeOverrides:getBounds in class RectangularShapeReturns:a new Rectangle, equal to the bounding Rectangle for this Rectangle.Since:1.1See Also:Component.getBounds(), setBounds(Rectangle), setBounds(int, int, int, int)getBounds2Dpublic Rectangle2D getBounds2D()Returns a high precision and more accurate bounding box of the Shape than the getBounds method. Note that there is no guarantee that the returned Rectangle2D is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle2D. The bounding box returned by this method is usually tighter than that returned by the getBounds method and never fails due to overflow problems since the return value can be an instance of the Rectangle2D that uses double precision values to store the dimensions. Note that the definition of insideness can lead to situations where points on the defining outline of the shape may not be considered contained in the returned bounds object, but only in cases where those points are also not considered contained in the original shape.
rectangle
041b061a72