Rectangle Class

Rectangle Class

This Package | All Packages

public class Rectangle
implements IPersistable, IConstructable

The Rectangle class is similar to a Win32 RECT structure. The Rectangle class also includes member functions to manipulate Rectangle objects and Win32 RECT structures. A Rectangle object also contains member variables that define the top, left, bottom, and right points of a rectangle.

Fields
Name Description
height Stores the height of the rectangle.
width Stores the width of the rectangle.
x Stores the x-position (or horizontal origin) of the rectangle.
y Stores the y-position (or vertical origin) of the rectangle.

Constructors
Name Description
Rectangle() Constructs a Rectangle object.
Rectangle(IDataStream stream) Constructs a Rectangle object and initializes the object from a data stream.
Rectangle(Rectangle r) Constructs a Rectangle object and initializes it to the specified Rectangle's settings.
Rectangle(int x, int y, int width, int height) Constructs a Rectangle object and initializes it to the settings contained in the specified Rectangle object.
Rectangle(RECT rect) Constructs a Rectangle object and initializes it to the settings stored in a Win32 RECT.

Methods
Name Description
contains(Point pt) Retrieves a boolean value that indicates whether this rectangle contains the specified points.
contains(int x, int y) Retrieves a boolean value that indicates whether this rectangle contains the specified points.
contains(Rectangle rect) Retrieves a boolean value that indicates whether the specified rectangle is less than or equal to this one.
equals(Object obj) Retrieves a boolean value that indicates whether the specified object is identical to this rectangle.
getBottom() Returns the lowest point in the rectangle's y-axis.
getConstructorArgs() Topic under construction.
getExtension() Because the Rectangle object is not a file-based object, this method always returns null.
getRight() Retrieves the right-most point on the rectangle's x-axis.
hashCode() Topic under construction.
inflateRect(int x, int y) Expands the size of the rectangle using the specified x and y values.
intersectRect(Rectangle lpRect1, Rectangle lpRect2) Retrieves a boolean value that indicates whether two rectangles intersect.
intersectsWith(Rectangle rect) Retrieves a boolean value that indicates whether the specified rectangle intersects with this one.
save(IDataStream stream) Saves this object's settings to a data stream.
setBounds(int x, int y, int width, int height) Initializes this Rectangle object.
setBounds(RECT r) Copies the specified values to this Rectangle object.
setBounds(Rectangle r) Copies the specified Rectangle object to this rectangle.
toRECT() Retrieves a Win32 RECT structure that contains the settings of this Rectangle object.
toRECT(Rectangle r) Retrieves a Win32 RECT structure that contains the settings of the specified Rectangle object.
toString() Retrieves a String representation of this object.

Fields

Rectangle.height

Syntax
public int height;
Description
Stores the height of the rectangle.

Rectangle.width

Syntax
public int width;
Description
Stores the width of the rectangle.

Rectangle.x

Syntax
public int x;
Description
Stores the x-position (or horizontal origin) of the rectangle.

Rectangle.y

Syntax
public int y;
Description
Stores the y-position (or vertical origin) of the rectangle.

Constructors

Rectangle.Rectangle

Syntax 1
public Rectangle();
Description

Constructs a Rectangle object.



Syntax 2
public Rectangle( IDataStream stream );
Description

Constructs a Rectangle object and initializes the object from a data stream.



Syntax 3
public Rectangle( Rectangle r );
Parameters
stream
The data stream from which to initialize the Rectangle.
Description

Constructs a Rectangle object and initializes it to the specified Rectangle's settings.



Syntax 4
public Rectangle( int x, int y, int width, int height );
Parameters
A
Rectangle object.
Description

Constructs a Rectangle object and initializes it to the settings contained in the specified Rectangle object.



Syntax 5
public Rectangle( RECT rect );
Parameters
rect
A Win32 RECT structure.
Description

Constructs a Rectangle object and initializes it to the settings stored in a Win32 RECT.

Methods

Rectangle.contains

Syntax 1
public boolean contains( Point pt );
Parameters
pt
A point that contains the x and y values to be compared.
Return Value

Returns true if this rectangle contains the specified coordinates; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether this rectangle contains the specified points. The x and y parameters in the pt parameter must be less than or equal to the x and y positions in the rectangle. In addition, the point's x value must be less than the rectangle's width and the point's y value must be less than the rectangle's height.



Syntax 2
public boolean contains( int x, int y );
Parameters
x
The x value to compare to the x-coordinate and width of the rectangle.
y
The y value to compare to the y-coordinate and height of the rectangle.
Return Value

Returns true, if the Rectangle contains the specified coordinates; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether this rectangle contains the specified points. The specified x and y parameters must be less than or equal to the x and y coordinates in the rectangle. In addition, the x and y parameters must be less than the width and height of the rectangle, respectively.



Syntax 3
public boolean contains( Rectangle rect );
Parameters
rect
The rectangle to compare to this one.
Return Value

Returns true if this rectangle contains the coordinates stored in the specified rectangle; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the specified rectangle is less than or equal to this one.

Rectangle.equals

Syntax
public boolean equals( Object obj );
Parameters
obj
The object to compare.
Return Value

Returns true if the objects are equivalent; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the specified object is identical to this rectangle. The specified object must be a Rectangle object instance.

Rectangle.getBottom

Syntax
public final int getBottom();
Return Value

Returns the lowest point in the rectangle's y-axis. This value equates to the sum of the rectangle's y-coordinate and its height.

Description

Returns the lowest point in the rectangle's y-axis.

Rectangle.getConstructorArgs

Syntax
public ConstructorArg[] getConstructorArgs();
Description

Topic under construction.

Rectangle.getExtension

Syntax
public String getExtension();
Return Value

Returns null.

Description

Because the Rectangle object is not a file-based object, this method always returns null.

Rectangle.getRight

Syntax
public final int getRight();
Return Value

Returns the right-most point on the rectangle's x-axis. This value equates to the sum of the rectangle's x-coordinate and its width.

Description

Retrieves the right-most point on the rectangle's x-axis.

Rectangle.hashCode

Syntax
public int hashCode();
Description

Topic under construction.

Rectangle.inflateRect

Syntax
public void inflateRect( int x, int y );
Parameters
x
The x value to use to formulate the rectangle's new x-coordinate and width.
y
The y value to use to formulate the rectangle's new y-coordinate and height.
Description

Expands the size of the rectangle using the specified x and y values. The inflateRect method formulates the new x and y coordinates by subtracting the value of the x and y parameters from the current value of the rectangle's x and y coordinates. The new width of the rectangle is formulated by adding the product of x and 2 to the current width. The new height is formulated by adding the product of y and 2 to the current height.

Rectangle.intersectRect

Syntax
public boolean intersectRect( Rectangle lpRect1, Rectangle lpRect2 );
Return Value

Returns true if the rectangles intersect; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether two rectangles intersect.

Rectangle.intersectsWith

Syntax
public boolean intersectsWith( Rectangle rect );
Parameters
rect
The rectangle to compare to this one.
Return Value

Returns true if the rectangles intersect; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the specified rectangle intersects with this one.

Rectangle.save

Syntax
public void save( IDataStream stream );
Parameters
stream
The data stream to which to save the settings.
Description

Saves this object's settings to a data stream.

Rectangle.setBounds

Syntax 1
public void setBounds( int x, int y, int width, int height );
Parameters
x
The x-coordinate for the rectangle.
y
The y-coordinate for the rectangle.
width
The width of the rectangle.
height
The height of the rectangle.
Description

Initializes this Rectangle object.



Syntax 2
public void setBounds( RECT r );
Parameters
r
The Win32 RECT structure that contains the values with which to initialize this rectangle.
Description

Copies the specified values to this Rectangle object.



Syntax 3
public void setBounds( Rectangle r );
Parameters
r
The Rectangle object to copy to this one.
Description

Copies the specified Rectangle object to this rectangle.

Rectangle.toRECT

Syntax 1
public final RECT toRECT();
Return Value

Returns a Win32 RECT structure that contains this rectangle's current values.

Description

Retrieves a Win32 RECT structure that contains the settings of this Rectangle object.



Syntax 2
public static final RECT toRECT( Rectangle r );
Return Value

Returns a Win32 RECT structure that contains the specified rectangle's settings.

Description

Retrieves a Win32 RECT structure that contains the settings of the specified Rectangle object.

Rectangle.toString

Syntax
public String toString();
Return Value

Returns a String representation of this Rectangle object.

Description

Retrieves a String representation of this object.