import java.awt.*; public class mPoint { // Instance variables: int x, y, dx, dy; Color color; // Constructor: public mPoint(int _x,int _y) { x =_x; y = _y; dx = 1; dy = 1; color = Color.black; } // Encapsulate the instance variables: public void setPoint(int _x, int _y) { x = _x; y = _y; } public void setDelta(int _dx, int _dy) { dx = _dx; dy = _dy; } public void setColor(Color _color) { color = _color; } // Class methods: public void move(Graphics g) { x += dx; y += dy; paint(g); } public void paint(Graphics g) { g.fillOval(x, y, 3, 3); // not used! } public void checkBoundary(Rectangle rect) { // Calculate new location: int nx = x + dx, ny = y + dy; // Check if new location out of bounds: if ( (nx < rect.x) || (nx >= rect.x + rect.width) ) dx = -dx; if ( (ny < rect.y) || (ny >= rect.y + rect.height) ) dy = -dy; } } // end of mPoint class