java.awt
Class Dimension

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.geom.Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D 
      extended by java.awt.Dimension
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable
Direct Known Subclasses:
DimensionUIResource sample code for javax.swing.plaf.DimensionUIResource definition code for javax.swing.plaf.DimensionUIResource

public class Dimension
extends Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

The Dimension class encapsulates the width and height of a component (in integer precision) in a single object. The class is associated with certain properties of components. Several methods defined by the Component class and the LayoutManager interface return a Dimension object.

Normally the values of width and height are non-negative integers. The constructors that allow you to create a dimension do not prevent you from setting a negative value for these properties. If the value of width or height is negative, the behavior of some methods defined by other objects is undefined.

Since:
JDK1.0
See Also:
Component sample code for java.awt.Component definition code for java.awt.Component , LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager , Serialized Form

Field Summary
 int height sample code for java.awt.Dimension.height definition code for java.awt.Dimension.height
          The height dimension; negative values can be used.
 int width sample code for java.awt.Dimension.width definition code for java.awt.Dimension.width
          The width dimension; negative values can be used.
 
Constructor Summary
Dimension sample code for java.awt.Dimension.Dimension() definition code for java.awt.Dimension.Dimension() ()
          Creates an instance of Dimension with a width of zero and a height of zero.
Dimension sample code for java.awt.Dimension.Dimension(java.awt.Dimension) definition code for java.awt.Dimension.Dimension(java.awt.Dimension) (Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  d)
          Creates an instance of Dimension whose width and height are the same as for the specified dimension.
Dimension sample code for java.awt.Dimension.Dimension(int, int) definition code for java.awt.Dimension.Dimension(int, int) (int width, int height)
          Constructs a Dimension and initializes it to the specified width and specified height.
 
Method Summary
 boolean equals sample code for java.awt.Dimension.equals(java.lang.Object) definition code for java.awt.Dimension.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Checks whether two dimension objects have equal values.
 double getHeight sample code for java.awt.Dimension.getHeight() definition code for java.awt.Dimension.getHeight() ()
          Returns the height of this dimension in double precision.
 Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension getSize sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize() ()
          Gets the size of this Dimension object.
 double getWidth sample code for java.awt.Dimension.getWidth() definition code for java.awt.Dimension.getWidth() ()
          Returns the width of this dimension in double precision.
 int hashCode sample code for java.awt.Dimension.hashCode() definition code for java.awt.Dimension.hashCode() ()
          Returns the hash code for this Dimension.
 void setSize sample code for java.awt.Dimension.setSize(java.awt.Dimension) definition code for java.awt.Dimension.setSize(java.awt.Dimension) (Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  d)
          Sets the size of this Dimension object to the specified size.
 void setSize sample code for java.awt.Dimension.setSize(double, double) definition code for java.awt.Dimension.setSize(double, double) (double width, double height)
          Sets the size of this Dimension object to the specified width and height in double precision.
 void setSize sample code for java.awt.Dimension.setSize(int, int) definition code for java.awt.Dimension.setSize(int, int) (int width, int height)
          Sets the size of this Dimension object to the specified width and height.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.Dimension.toString() definition code for java.awt.Dimension.toString() ()
          Returns a string representation of the values of this Dimension object's height and width fields.
 
Methods inherited from class java.awt.geom.Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D
clone sample code for java.awt.geom.Dimension2D.clone() definition code for java.awt.geom.Dimension2D.clone() , setSize sample code for java.awt.geom.Dimension2D.setSize(java.awt.geom.Dimension2D) definition code for java.awt.geom.Dimension2D.setSize(java.awt.geom.Dimension2D)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

width sample code for java.awt.Dimension.width

public int width
The width dimension; negative values can be used.

See Also:
getSize() sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize() , setSize(double, double) sample code for java.awt.Dimension.setSize(double, double) definition code for java.awt.Dimension.setSize(double, double)

height sample code for java.awt.Dimension.height

public int height
The height dimension; negative values can be used.

See Also:
getSize() sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize() , setSize(double, double) sample code for java.awt.Dimension.setSize(double, double) definition code for java.awt.Dimension.setSize(double, double)
Constructor Detail

Dimension sample code for java.awt.Dimension() definition code for java.awt.Dimension()

public Dimension()
Creates an instance of Dimension with a width of zero and a height of zero.


Dimension sample code for java.awt.Dimension(java.awt.Dimension) definition code for java.awt.Dimension(java.awt.Dimension)

public Dimension(Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  d)
Creates an instance of Dimension whose width and height are the same as for the specified dimension.

Parameters:
d - the specified dimension for the width and height values

Dimension sample code for java.awt.Dimension(int, int) definition code for java.awt.Dimension(int, int)

public Dimension(int width,
                 int height)
Constructs a Dimension and initializes it to the specified width and specified height.

Parameters:
width - the specified width
height - the specified height
Method Detail

getWidth sample code for java.awt.Dimension.getWidth() definition code for java.awt.Dimension.getWidth()

public double getWidth()
Returns the width of this dimension in double precision.

Specified by:
getWidth sample code for java.awt.geom.Dimension2D.getWidth() definition code for java.awt.geom.Dimension2D.getWidth() in class Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D
Returns:
the width of this dimension in double precision

getHeight sample code for java.awt.Dimension.getHeight() definition code for java.awt.Dimension.getHeight()

public double getHeight()
Returns the height of this dimension in double precision.

Specified by:
getHeight sample code for java.awt.geom.Dimension2D.getHeight() definition code for java.awt.geom.Dimension2D.getHeight() in class Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D
Returns:
the height of this dimension in double precision

setSize sample code for java.awt.Dimension.setSize(double, double) definition code for java.awt.Dimension.setSize(double, double)

public void setSize(double width,
                    double height)
Sets the size of this Dimension object to the specified width and height in double precision. Note that if width or height are larger than Integer.MAX_VALUE, they will be reset to Integer.MAX_VALUE.

Specified by:
setSize sample code for java.awt.geom.Dimension2D.setSize(double, double) definition code for java.awt.geom.Dimension2D.setSize(double, double) in class Dimension2D sample code for java.awt.geom.Dimension2D definition code for java.awt.geom.Dimension2D
Parameters:
width - the new width for the Dimension object
height - the new height for the Dimension object

getSize sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize()

public Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  getSize()
Gets the size of this Dimension object. This method is included for completeness, to parallel the getSize method defined by Component.

Returns:
the size of this dimension, a new instance of Dimension with the same width and height
Since:
JDK1.1
See Also:
setSize(double, double) sample code for java.awt.Dimension.setSize(double, double) definition code for java.awt.Dimension.setSize(double, double) , Component.getSize() sample code for java.awt.Component.getSize() definition code for java.awt.Component.getSize()

setSize sample code for java.awt.Dimension.setSize(java.awt.Dimension) definition code for java.awt.Dimension.setSize(java.awt.Dimension)

public void setSize(Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  d)
Sets the size of this Dimension object to the specified size. This method is included for completeness, to parallel the setSize method defined by Component.

Parameters:
d - the new size for this Dimension object
Since:
JDK1.1
See Also:
getSize() sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize() , Component.setSize(int, int) sample code for java.awt.Component.setSize(int, int) definition code for java.awt.Component.setSize(int, int)

setSize sample code for java.awt.Dimension.setSize(int, int) definition code for java.awt.Dimension.setSize(int, int)

public void setSize(int width,
                    int height)
Sets the size of this Dimension object to the specified width and height. This method is included for completeness, to parallel the setSize method defined by Component.

Parameters:
width - the new width for this Dimension object
height - the new height for this Dimension object
Since:
JDK1.1
See Also:
getSize() sample code for java.awt.Dimension.getSize() definition code for java.awt.Dimension.getSize() , Component.setSize(int, int) sample code for java.awt.Component.setSize(int, int) definition code for java.awt.Component.setSize(int, int)

equals sample code for java.awt.Dimension.equals(java.lang.Object) definition code for java.awt.Dimension.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Checks whether two dimension objects have equal values.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

hashCode sample code for java.awt.Dimension.hashCode() definition code for java.awt.Dimension.hashCode()

public int hashCode()
Returns the hash code for this Dimension.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code for this Dimension
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

toString sample code for java.awt.Dimension.toString() definition code for java.awt.Dimension.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a string representation of the values of this Dimension object's height and width fields. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of this Dimension object