com.sun.lwuit.geom
Class Rectangle

java.lang.Object
  extended by com.sun.lwuit.geom.Rectangle

public class Rectangle
extends java.lang.Object

Represents a Rectangle position (x, y) and Dimension (width, height), this is useful for measuring coordinates within the application.


Constructor Summary
Rectangle()
          Creates a new instance of Rectangle
Rectangle(int x, int y, Dimension size)
          Creates a new instance of Rectangle at position (x, y) and with predefine dimension
Rectangle(int x, int y, int w, int h)
          Creates a new instance of Rectangle at position (x, y) and with predefine width and height
Rectangle(Rectangle rect)
          A copy Constructor
 
Method Summary
 boolean contains(int rX, int rY)
          Checks whether or not this Rectangle contains the point at the specified location (rX, rY).
 boolean contains(int rX, int rY, int rWidth, int rHeight)
          Checks whether this Rectangle entirely contains the Rectangle at the specified location (rX, rY) with the specified dimensions (rWidth, rHeight).
static boolean contains(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
          Checks wheather the 2nd rectangle is contained in the first rectangle
 boolean contains(Rectangle rect)
          Checks whether or not this Rectangle entirely contains the specified Rectangle.
 Dimension getSize()
          Return the dimension of the rectangle
 int getX()
          Return the x coordinate of the rectangle
 int getY()
          Return the y coordinate of the rectangle
 Rectangle intersection(int rX, int rY, int rW, int rH)
          Returns a rectangle that intersects the given rectangle with this rectangle
 Rectangle intersection(Rectangle r)
          Returns a rectangle that intersects the given rectangle with this rectangle
 boolean intersects(int x, int y, int width, int height)
          Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect.
static boolean intersects(int tx, int ty, int tw, int th, int x, int y, int width, int height)
          Helper method allowing us to determine if two coordinate sets intersect.
 boolean intersects(Rectangle rect)
          Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect.
 void setX(int x)
          Sets the x position of the rectangle
 void setY(int y)
          Sets the y position of the rectangle
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rectangle

public Rectangle()
Creates a new instance of Rectangle


Rectangle

public Rectangle(int x,
                 int y,
                 Dimension size)
Creates a new instance of Rectangle at position (x, y) and with predefine dimension

Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
size - the Dimension of the rectangle

Rectangle

public Rectangle(int x,
                 int y,
                 int w,
                 int h)
Creates a new instance of Rectangle at position (x, y) and with predefine width and height

Parameters:
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
w - the width of the rectangle
h - the height of the rectangle

Rectangle

public Rectangle(Rectangle rect)
A copy Constructor

Parameters:
rect - the Rectangle to copy
Method Detail

getSize

public Dimension getSize()
Return the dimension of the rectangle

Returns:
the size of the rectangle

getX

public int getX()
Return the x coordinate of the rectangle

Returns:
the x coordinate of the rectangle

getY

public int getY()
Return the y coordinate of the rectangle

Returns:
the y coordinate of the rectangle

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setX

public void setX(int x)
Sets the x position of the rectangle

Parameters:
x - the x coordinate of the rectangle

setY

public void setY(int y)
Sets the y position of the rectangle

Parameters:
y - the y coordinate of the rectangle

contains

public boolean contains(Rectangle rect)
Checks whether or not this Rectangle entirely contains the specified Rectangle.

Parameters:
rect - the specified Rectangle
Returns:
true if the Rectangle is contained entirely inside this Rectangle; false otherwise

contains

public boolean contains(int rX,
                        int rY,
                        int rWidth,
                        int rHeight)
Checks whether this Rectangle entirely contains the Rectangle at the specified location (rX, rY) with the specified dimensions (rWidth, rHeight).

Parameters:
rX - the specified x coordinate
rY - the specified y coordinate
rWidth - the width of the Rectangle
rHeight - the height of the Rectangle
Returns:
true if the Rectangle specified by (rX, rY, rWidth, rHeight) is entirely enclosed inside this Rectangle; false otherwise.

contains

public static boolean contains(int x1,
                               int y1,
                               int w1,
                               int h1,
                               int x2,
                               int y2,
                               int w2,
                               int h2)
Checks wheather the 2nd rectangle is contained in the first rectangle

Parameters:
x1 - first rect x
y1 - first rect y
w1 - first rect w
h1 - first rect h
x2 - second rect x
y2 - second rect y
w2 - second rect w
h2 - second rect h
Returns:
true if x2, y2, w2, h2 is contained in x1, y1, w1, h1

contains

public boolean contains(int rX,
                        int rY)
Checks whether or not this Rectangle contains the point at the specified location (rX, rY).

Parameters:
rX - the specified x coordinate
rY - the specified y coordinate
Returns:
true if the point (rX, rY) is inside this Rectangle; false otherwise.

intersection

public Rectangle intersection(int rX,
                              int rY,
                              int rW,
                              int rH)
Returns a rectangle that intersects the given rectangle with this rectangle

Parameters:
rX - rectangle to intersect with this rectangle
rY - rectangle to intersect with this rectangle
rW - rectangle to intersect with this rectangle
rH - rectangle to intersect with this rectangle
Returns:
the intersection

intersection

public Rectangle intersection(Rectangle r)
Returns a rectangle that intersects the given rectangle with this rectangle

Parameters:
r - rectangle to intersect with this rectangle
Returns:
the intersection

intersects

public boolean intersects(int x,
                          int y,
                          int width,
                          int height)
Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect. Two rectangles intersect if their intersection is nonempty.

Parameters:
x - the specified x coordinate
y - the specified y coordinate
width - the width of the Rectangle
height - the height of the Rectangle
Returns:
true if the specified Rectangle and this Rectangle intersect; false otherwise.

intersects

public boolean intersects(Rectangle rect)
Determines whether or not this Rectangle and the specified Rectangle location (x, y) with the specified dimensions (width, height), intersect. Two rectangles intersect if their intersection is nonempty.

Parameters:
rect - the Rectangle to check intersection with
Returns:
true if the specified Rectangle and this Rectangle intersect; false otherwise.

intersects

public static boolean intersects(int tx,
                                 int ty,
                                 int tw,
                                 int th,
                                 int x,
                                 int y,
                                 int width,
                                 int height)
Helper method allowing us to determine if two coordinate sets intersect. This saves us the need of creating a rectangle object for a quick calculation

Parameters:
tx - x of first rectangle
ty - y of first rectangle
tw - width of first rectangle
th - height of first rectangle
x - x of second rectangle
y - y of second rectangle
width - width of second rectangle
height - height of second rectangle
Returns:
true if the rectangles intersect