import java.awt.*; public class Ball { public Ball (Point lc, int r) { loc = lc; rad = r; } protected Point loc; // position in window protected int rad; // radius protected double changeInX = 0.0; protected double changeInY = 0.0; protected Color color = Color.blue; // color of ball public void setColor (Color newColor) { color = newColor; } public void setMotion (double dx, double dy) { changeInX = dx; changeInY = dy; } public int radius () { return rad; } public Point location () { return loc; } public void reflectHorz () { changeInX = - changeInX; } public void reflectVert () { changeInY = - changeInY; } public int x () { return loc.x; } public int y () { return loc.y; } public void moveTo (int x, int y) { loc.move(x, y); } public void move () { loc.translate((int) changeInX, (int) changeInY); } public void paint (Graphics g) { g.setColor (color); g.fillOval (loc.x-rad, loc.y-rad, 2*rad, 2*rad); } }