home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 February / VPR9802A.ISO / APP_DEMO / VC / MAIN.BIN / Dimension.java < prev    next >
Text File  |  1997-10-27  |  3KB  |  124 lines

  1. /*
  2.  * @(#)Dimension.java    1.12 97/01/27
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22. package java.awt;
  23.  
  24. /**
  25.  * A class to encapsulate a width and a height Dimension.
  26.  * 
  27.  * @version     1.12, 01/27/97
  28.  * @author     Sami Shaio
  29.  * @author     Arthur van Hoff
  30.  */
  31. public class Dimension implements java.io.Serializable {
  32.     
  33.     /**
  34.      * The width dimension.
  35.      */
  36.     public int width;
  37.  
  38.     /**
  39.      * The height dimension.
  40.      */
  41.     public int height;
  42.  
  43.     /*
  44.      * JDK 1.1 serialVersionUID 
  45.      */
  46.      private static final long serialVersionUID = 4723952579491349524L;
  47.  
  48.     /** 
  49.      * Constructs a Dimension object with 0 width and 0 height.
  50.      */
  51.     public Dimension() {
  52.     this(0, 0);
  53.     }
  54.  
  55.     /** 
  56.      * Constructs a Dimension and initializes it to the specified value.
  57.      * @param d the specified dimension for the width and height values
  58.      */
  59.     public Dimension(Dimension d) {
  60.     this(d.width, d.height);
  61.     }
  62.  
  63.     /** 
  64.      * Constructs a Dimension and initializes it to the specified width and
  65.      * specified height.
  66.      * @param width the specified width dimension
  67.      * @param height the specified height dimension
  68.      */
  69.     public Dimension(int width, int height) {
  70.     this.width = width;
  71.     this.height = height;
  72.     }
  73.  
  74.     /**
  75.      * Returns the size of this Dimension object.
  76.      * This method is included for completeness, to parallel the
  77.      * getSize method of Component.
  78.      */
  79.     public Dimension getSize() {
  80.     return new Dimension(width, height);
  81.     }    
  82.  
  83.     /**
  84.      * Set the size of this Dimension object to match the specified size.
  85.      * This method is included for completeness, to parallel the
  86.      * getSize method of Component.
  87.      * @param d  the new size for the Dimension object
  88.      */
  89.     public void setSize(Dimension d) {
  90.     setSize(d.width, d.height);
  91.     }    
  92.  
  93.     /**
  94.      * Set the size of this Dimension object to the specified width
  95.      * and height.
  96.      * This method is included for completeness, to parallel the
  97.      * getSize method of Component.
  98.      * @param width  the new width for the Dimension object
  99.      * @param height  the new height for the Dimension object
  100.      */
  101.     public void setSize(int width, int height) {
  102.         this.width = width;
  103.         this.height = height;
  104.     }    
  105.  
  106.     /**
  107.      * Checks whether two dimension objects have equal values.
  108.      */
  109.     public boolean equals(Object obj) {
  110.     if (obj instanceof Dimension) {
  111.         Dimension d = (Dimension)obj;
  112.         return (width == d.width) && (height == d.height);
  113.     }
  114.     return false;
  115.     }
  116.  
  117.     /**
  118.      * Returns the String representation of this Dimension's values.
  119.      */
  120.     public String toString() {
  121.     return getClass().getName() + "[width=" + width + ",height=" + height + "]";
  122.     }
  123. }
  124.