/* mPoint.java */ import java.awt.*; public class mPoint { int x, y; int dx = 2, dy = 2; Color color = Color.black; public mPoint(int _x, int _y) { /* initial location */ x = _x; y = _y; } public void setDelta(int _dx, int _dy) { dx = _dx; dy = _dy; } public void setColor(Color _color) { color = _color;} /* check if object collide boundry */ public void checkBoundry(Rectangle rect) { int nx = x+dx; /* caculate new location */ int ny = y+dy; /* check if new location out of boundry */ if ( (nx < rect.x) || (nx >= rect.x+rect.width) ) dx = -dx; if ( (ny < rect.y) || (ny >= rect.y+rect.height) ) dy = -dy; } /* move object */ public void move(Graphics g) { paint(g); /* use XOR to hide object */ x += dx; /* update location */ y += dy; new_paint(g); /* draw object on new location */ } public void paint(Graphics g) {} public void new_paint(Graphics g) {} }