1 /* mPoint.java */ 2 3 import java.awt.*; 4 5 public class mPoint { 6 int x, y; 7 Color color = Color.black; 8 public mPoint(int _x, int _y) { 9 /* initial location */ 10 x = _x; 11 y = _y; 12 } 13 public void setColor(Color _color) { color = _color;} 14 public void setColor(Graphics g, Color _color) { 15 if ( _color == color ) return; 16 paint(g); /* use XOR to hide object */ 17 color = _color; 18 paint(g); /* draw object on new location */ 19 } 20 /* check if position inside object */ 21 public boolean isInside(int _x, int _y) { 22 return (x == _x) && (y == _y); 23 } 24 /* move object */ 25 public void moveTo(Graphics g, int _x, int _y) { 26 if ( (x == _x) && (y == _y) ) return; 27 paint(g); /* use XOR to hide object */ 28 x = _x; /* update location */ 29 y = _y; 30 paint(g); /* draw object on new location */ 31 } 32 public void move(Graphics g, int dx, int dy) { 33 if ( (dx == 0) && (dy == 0) ) return; 34 paint(g); /* use XOR to hide object */ 35 x += dx; /* update location */ 36 y += dy; 37 paint(g); /* draw object on new location */ 38 } 39 public void paint(Graphics g) {} 40 }