home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / Point.java < prev    next >
Text File  |  1996-05-03  |  2KB  |  90 lines

  1. /*
  2.  * @(#)Point.java    1.8 95/12/14 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. /**
  22.  * An x,y coordinate.
  23.  *
  24.  * @version     1.8, 14 Dec 1995
  25.  * @author     Sami Shaio
  26.  */
  27. public class Point {
  28.     /**
  29.      * The x coordinate.
  30.      */
  31.     public int x;
  32.  
  33.     /**
  34.      * The y coordinate.
  35.      */
  36.     public int y;
  37.  
  38.     /**
  39.      * Constructs and initializes a Point from the specified x and y 
  40.      * coordinates.
  41.      * @param x the x coordinate
  42.      * @param y the y coordinate
  43.      */
  44.     public Point(int x, int y) {
  45.     this.x = x;
  46.     this.y = y;
  47.     }
  48.  
  49.     /**
  50.      * Moves the point.
  51.      */
  52.     public void move(int x, int y) {
  53.     this.x = x;
  54.     this.y = y;
  55.     }    
  56.  
  57.     /**
  58.      * Translates the point.
  59.      */
  60.     public void translate(int x, int y) {
  61.     this.x += x;
  62.     this.y += y;
  63.     }    
  64.  
  65.     /**
  66.      * Returns the hashcode for this Point.
  67.      */
  68.     public int hashCode() {
  69.     return x ^ (y*31);
  70.     }
  71.  
  72.     /**
  73.      * Checks whether two pointers are equal.
  74.      */
  75.     public boolean equals(Object obj) {
  76.     if (obj instanceof Point) {
  77.         Point pt = (Point)obj;
  78.         return (x == pt.x) && (y == pt.y);
  79.     }
  80.     return false;
  81.     }
  82.  
  83.     /**
  84.      * Returns the String representation of this Point's coordinates.
  85.      */
  86.     public String toString() {
  87.     return getClass().getName() + "[x=" + x + ",y=" + y + "]";
  88.     }
  89. }
  90.