public class Dimension extends Dimension2D implements Serializable
It is valid for a dimension to have negative width or height; but it is considered to have no area. Therefore, the behavior in various methods is undefined in such a case.
There are some public fields; if you mess with them in an inconsistent manner, it is your own fault when you get invalid results. Also, this class is not threadsafe.
Component,
LayoutManager,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
int |
height
The height of this object.
|
int |
width
The width of this object.
|
| Constructor and Description |
|---|
Dimension()
Create a new Dimension with a width and height of zero.
|
Dimension(Dimension d)
Create a new Dimension with width and height identical to that of the
specified dimension.
|
Dimension(int w,
int h)
Create a new Dimension with the specified width and height.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Tests this object for equality against the specified object.
|
double |
getHeight()
Gets the height of this dimension.
|
Dimension |
getSize()
Returns the size of this dimension.
|
double |
getWidth()
Gets the width of this dimension.
|
int |
hashCode()
Return the hashcode for this object.
|
void |
setSize(Dimension d)
Sets the width and height of this object to match that of the
specified object.
|
void |
setSize(double w,
double h)
Sets the size of this dimension.
|
void |
setSize(int w,
int h)
Sets the width and height of this object to the specified values.
|
String |
toString()
Returns a string representation of this object.
|
clone, setSizepublic int width
getSize(),
setSize(double, double)public int height
getSize(),
setSize(double, double)public Dimension()
public Dimension(Dimension d)
d - the Dimension to copyNullPointerException - if d is nullpublic Dimension(int w, int h)
w - the width of this objecth - the height of this objectpublic double getWidth()
getWidth in class Dimension2Dpublic double getHeight()
getHeight in class Dimension2Dpublic void setSize(double w, double h)
setSize in class Dimension2Dw - the new widthh - the new heightpublic Dimension getSize()
setSize(Dimension)public void setSize(Dimension d)
d - the Dimension to get the new width and height fromNullPointerException - if d is nullgetSize()public void setSize(int w, int h)
w - the new width valueh - the new height valuepublic boolean equals(Object obj)
equals in class Objectobj - the object to test againstObject.hashCode()public int hashCode()
((width + height) * (width + height + 1) / 2) + width.hashCode in class ObjectObject.equals(Object),
System.identityHashCode(Object)public String toString()
getClass().getName() + "[width=" + width + ",height=" + height
+ ']'.toString in class ObjectObject.getClass(),
Object.hashCode(),
Class.getName(),
Integer.toHexString(int)