1 19 package swingwt.awt; 20 21 public class Point extends swingwt.awt.geom.Point2D { 22 23 public int x; 24 public int y; 25 public Point() { 26 this(0, 0); 27 } 28 public Point(Point p) { 29 this(p.x, p.y); 30 } 31 public Point(int x, int y) { 32 this.x = x; 33 this.y = y; 34 } 35 public double getX() { 36 return x; 37 } 38 public double getY() { 39 return y; 40 } 41 public Point getLocation() { 42 return new Point(x, y); 43 } 44 public void setLocation(Point p) { 45 setLocation(p.x, p.y); 46 } 47 public void setLocation(int x, int y) { 48 move(x, y); 49 } 50 public void setLocation(double x, double y) { 51 this.x = (int) Math.floor(x+0.5); 52 this.y = (int) Math.floor(y+0.5); 53 } 54 public void move(int x, int y) { 55 this.x = x; 56 this.y = y; 57 } 58 public void translate(int dx, int dy) { 59 this.x += dx; 60 this.y += dy; 61 } 62 public boolean equals(Object obj) { 63 if (obj instanceof Point) { 64 Point pt = (Point)obj; 65 return (x == pt.x) && (y == pt.y); 66 } 67 return super.equals(obj); 68 } 69 public String toString() { 70 return getClass().getName() + "[x=" + x + ",y=" + y + "]"; 71 } 72 } | Popular Tags |