1 7 8 package java.awt; 9 10 import java.awt.geom.Point2D ; 11 12 20 public class Point extends Point2D implements java.io.Serializable { 21 29 public int x; 30 31 39 public int y; 40 41 44 private static final long serialVersionUID = -5276940640259749850L; 45 46 51 public Point() { 52 this(0, 0); 53 } 54 55 61 public Point(Point p) { 62 this(p.x, p.y); 63 } 64 65 71 public Point(int x, int y) { 72 this.x = x; 73 this.y = y; 74 } 75 76 80 public double getX() { 81 return x; 82 } 83 84 88 public double getY() { 89 return y; 90 } 91 92 102 public Point getLocation() { 103 return new Point (x, y); 104 } 105 106 115 public void setLocation(Point p) { 116 setLocation(p.x, p.y); 117 } 118 119 132 public void setLocation(int x, int y) { 133 move(x, y); 134 } 135 136 148 public void setLocation(double x, double y) { 149 this.x = (int) Math.floor(x+0.5); 150 this.y = (int) Math.floor(y+0.5); 151 } 152 153 161 public void move(int x, int y) { 162 this.x = x; 163 this.y = y; 164 } 165 166 177 public void translate(int dx, int dy) { 178 this.x += dx; 179 this.y += dy; 180 } 181 182 192 public boolean equals(Object obj) { 193 if (obj instanceof Point ) { 194 Point pt = (Point )obj; 195 return (x == pt.x) && (y == pt.y); 196 } 197 return super.equals(obj); 198 } 199 200 209 public String toString() { 210 return getClass().getName() + "[x=" + x + ",y=" + y + "]"; 211 } 212 } 213 | Popular Tags |