home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Dimension.java < prev    next >
Text File  |  1997-10-01  |  6KB  |  163 lines

  1. /*
  2.  * @(#)Dimension.java    1.13 97/06/12
  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.  * The <code>Dimension</code> class encapsulates the width and 
  26.  * height of a component in a single object. The class is 
  27.  * associated with certain properties of components. Several methods 
  28.  * defined by the <code>Component</code> class and the 
  29.  * <code>LayoutManager</code> interface return a 
  30.  * <code>Dimension</code> object. 
  31.  * <p>
  32.  * Normally the values of <code>width</code> 
  33.  * and <code>height</code> are non-negative integers. 
  34.  * The constructors that allow you to create a dimension do 
  35.  * not prevent you from setting a negative value for these properties. 
  36.  * If the value of <code>width</code> or <code>height</code> is 
  37.  * negative, the behavior of some methods defined by other objects is 
  38.  * undefined. 
  39.  * 
  40.  * @version     1.13, 06/12/97
  41.  * @author     Sami Shaio
  42.  * @author     Arthur van Hoff
  43.  * @see         java.awt.Component
  44.  * @see         java.awt.LayoutManager
  45.  * @since       JDK1.0
  46.  */
  47. public class Dimension implements java.io.Serializable {
  48.     
  49.     /**
  50.      * The width dimension.
  51.      */
  52.     public int width;
  53.  
  54.     /**
  55.      * The height dimension.
  56.      */
  57.     public int height;
  58.  
  59.     /*
  60.      * JDK 1.1 serialVersionUID 
  61.      */
  62.      private static final long serialVersionUID = 4723952579491349524L;
  63.  
  64.     /** 
  65.      * Creates an instance of <code>Dimension</code> with a width 
  66.      * of zero and a height of zero. 
  67.      * @since   JDK1.0
  68.      */
  69.     public Dimension() {
  70.     this(0, 0);
  71.     }
  72.  
  73.     /** 
  74.      * Creates an instance of <code>Dimension</code> whose width  
  75.      * and height are the same as for the specified dimension. 
  76.      * @param    d   the specified dimension for the 
  77.      *               <code>width</code> and 
  78.      *               <code>height</code> values.
  79.      * @since    JDK1.0
  80.      */
  81.     public Dimension(Dimension d) {
  82.     this(d.width, d.height);
  83.     }
  84.  
  85.     /** 
  86.      * Constructs a Dimension and initializes it to the specified width and
  87.      * specified height.
  88.      * @param width the specified width dimension
  89.      * @param height the specified height dimension
  90.      * @since JDK1.0
  91.      */
  92.     public Dimension(int width, int height) {
  93.     this.width = width;
  94.     this.height = height;
  95.     }
  96.  
  97.     /**
  98.      * Gets the size of this <code>Dimension</code> object.
  99.      * This method is included for completeness, to parallel the
  100.      * <code>getSize</code> method defined by <code>Component</code>.
  101.      * @return   the size of this dimension, a new instance of 
  102.      *           <code>Dimension</code> with the same width and height.
  103.      * @see      java.awt.Dimension#setSize
  104.      * @see      java.awt.Component#getSize
  105.      * @since    JDK1.1
  106.      */
  107.     public Dimension getSize() {
  108.     return new Dimension(width, height);
  109.     }    
  110.  
  111.     /**
  112.      * Set the size of this <code>Dimension</code> object to the specified size.
  113.      * This method is included for completeness, to parallel the
  114.      * <code>setSize</code> method defined by <code>Component</code>.
  115.      * @param    d  the new size for this <code>Dimension</code> object.
  116.      * @see      java.awt.Dimension#getSize
  117.      * @see      java.awt.Component#setSize
  118.      * @since    JDK1.1
  119.      */
  120.     public void setSize(Dimension d) {
  121.     setSize(d.width, d.height);
  122.     }    
  123.  
  124.     /**
  125.      * Set the size of this <code>Dimension</code> object 
  126.      * to the specified width and height.
  127.      * This method is included for completeness, to parallel the
  128.      * <code>setSize</code> method defined by <code>Component</code>.
  129.      * @param    width   the new width for this <code>Dimension</code> object.
  130.      * @param    height  the new height for this <code>Dimension</code> object.
  131.      * @see      java.awt.Dimension#getSize
  132.      * @see      java.awt.Component#setSize
  133.      * @since    JDK1.1
  134.      */
  135.     public void setSize(int width, int height) {
  136.         this.width = width;
  137.         this.height = height;
  138.     }    
  139.  
  140.     /**
  141.      * Checks whether two dimension objects have equal values.
  142.      */
  143.     public boolean equals(Object obj) {
  144.     if (obj instanceof Dimension) {
  145.         Dimension d = (Dimension)obj;
  146.         return (width == d.width) && (height == d.height);
  147.     }
  148.     return false;
  149.     }
  150.  
  151.     /**
  152.      * Returns a string that represents this 
  153.      * <code>Dimension</code> object's values.
  154.      * @return     a string representation of this dimension, 
  155.      *                  including the values of <code>width</code> 
  156.      *                  and <code>height</code>.
  157.      * @since      JDK1.0
  158.      */
  159.     public String toString() {
  160.     return getClass().getName() + "[width=" + width + ",height=" + height + "]";
  161.     }
  162. }
  163.