Dimension
Name
Dimension
Description
The Dimension
class encapsulates width and height in a single object.
Class Definition
public class java.awt.Dimension extends java.lang.Object implements java.io.Serializable { // Variables public int height; public int width; // Constructors public Dimension(); public Dimension (int width, int height); public Dimension (Dimension d); // Instance Methods public boolean equals (Object obj); public Dimension getSize(); public void setSize (Dimension d); public void setSize (int width, int height); public String toString(); }
Variables
height
public int height
The height of the Dimension
.
width
public int width
The width of the Dimension
.
Constructors
Dimension
public Dimension()
- Description
- Constructs an empty
Dimension
object.
public Dimension (int width, int height)
- Parameters
-
- width
- Initial width of the object
- height
- Initial height of the object
- Description
- Constructs a
Dimension
object with an initial dimension ofwidth
xheight
.
public Dimension (Dimension d)
- Parameters
-
- d
- Initial dimensions of the object
- Description
- Constructs a
Dimension
object that is a clone ofd
.
Instance Methods
equals
public boolean equals (Object obj)
- Parameters
-
- obj
- The object to compare.
- Returns
true
if thisDimension
is equivalent toobj
; false otherwise.- Overrides
Object.equals(Object)
- Description
- Compares two
Dimension
instances.
getSize
public Dimension getSize()
- Returns
- The size of the
Dimension
.
setSize
public void setSize (Dimension d)
- Parameters
-
- d
- The new size.
- Description
- Changes the size of the
Dimension
.
public void setSize (int width, int height)
- Parameters
-
- width
- The new width.
- height
- The new height.
- Description
- Changes the size of the
Dimension
.
toString
public String toString()
- Returns
- A string representation of the
Dimension
object. - Overrides
Object.toString()
See Also
Object
, String
, Serializable