acm.graphics
Class GDimension

java.lang.Object
  extended by acm.graphics.GDimension
All Implemented Interfaces:
Serializable

public class GDimension
extends Object
implements Serializable

This class is a double-precision version of the Dimension class in java.awt.

See Also:
Serialized Form

Constructor Summary
GDimension()
          Constructs a new dimension object with zero values for width and height.
GDimension(Dimension size)
          Constructs a new GDimension object from an AWT Dimension.
GDimension(double width, double height)
          Constructs a new dimension object with the specified components.
GDimension(GDimension size)
          Constructs a new GDimension object from an existing one.
 
Method Summary
 boolean equals(Object obj)
          Tests whether two GDimension objects are equal.
 double getHeight()
          Returns the height of this GDimension.
 GDimension getSize()
          Returns a new GDimension object equal to this one.
 double getWidth()
          Returns the width of this GDimension.
 int hashCode()
          Returns an integer hash code for the dimension object.
 void setSize(double width, double height)
          Sets the components of the dimension object from the specified parameters.
 void setSize(GDimension size)
          Sets the width and height of one GDimension object equal to that of another.
 Dimension toDimension()
          Converts this GDimension to the nearest integer-based Dimension.
 String toString()
          Converts this GDimension to its string representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GDimension

public GDimension()
Constructs a new dimension object with zero values for width and height.


GDimension

public GDimension(Dimension size)
Constructs a new GDimension object from an AWT Dimension.

Parameters:
size - An AWT Dimension object specifying the size

GDimension

public GDimension(double width,
                  double height)
Constructs a new dimension object with the specified components.

Parameters:
width - The width of the dimension object
height - The height of the dimension object

GDimension

public GDimension(GDimension size)
Constructs a new GDimension object from an existing one.

Parameters:
size - An existing GDimension object specifying the size
Method Detail

equals

public boolean equals(Object obj)
Tests whether two GDimension objects are equal. Because floating-point values are inexact, this method checks for equality by comparing the float values (rather than the double values) of the coordinates.

Overrides:
equals in class Object
Parameters:
obj - Any object
Returns:
true if the obj is a GDimension equal to this one, and false otherwise

getHeight

public double getHeight()
Returns the height of this GDimension.

Returns:
The height of this GDimension

getSize

public GDimension getSize()
Returns a new GDimension object equal to this one.

Returns:
A new GDimension object with the same size

getWidth

public double getWidth()
Returns the width of this GDimension.

Returns:
The width of this GDimension

hashCode

public int hashCode()
Returns an integer hash code for the dimension object. The hash code for a GDimension is constructed from the hash codes from the float values of the width and height, which are the ones used in the equals method.

Overrides:
hashCode in class Object
Returns:
The hash code for this dimension object

setSize

public void setSize(double width,
                    double height)
Sets the components of the dimension object from the specified parameters.

Parameters:
width - The new width of the dimension object
height - The new height of the dimension object

setSize

public void setSize(GDimension size)
Sets the width and height of one GDimension object equal to that of another.

Parameters:
size - A GDimension object specifying the new size

toDimension

public Dimension toDimension()
Converts this GDimension to the nearest integer-based Dimension.

Returns:
The closest integer-based Dimension object

toString

public String toString()
Converts this GDimension to its string representation.

Overrides:
toString in class Object
Returns:
A string representation of this dimension object