2 |
public class mPoint { /* Continue as before and add */
-
public void setColor(Color color) { this.color = color;}
-
public void checkBoundry(Rectangle rect) { /* check if object crosses boundary */
-
int nx = x+dx; /* caculate new location */
-
int ny = y+dy;
-
if ( (nx < rect.x) || (nx >= rect.x+rect.width) ) dx = -dx;
-
if ( (ny < rect.y) || (ny >= rect.y+rect.height) ) dy = -dy;
-
}
-
public void move(Graphics g) { /* move object */
-
paint(g); /* use XOR to hide object */
-
x += dx; /* update location */
-
y += dy;
-
paint(g); /* draw object on new location */
-
}
-
public void paint(Graphics g) {}
|