// A simple class to hold the ball definition public class Ball { public int dir = 1; // direction of travel public double x=0; // current X public double y=0; // current y public int maxheight=100; // Y limit public int maxwidth=100; // X limit public double speed=.1; // step size for X public java.awt.Color color; // color public void step() { x+=dir * speed; // move X to next spot if (x>maxwidth) // bounce off left/right wall { x-=speed; dir=-dir; } else if (x<0) { x+=speed; dir=-dir; } // describe bouncing with a sine wave y=Math.abs(Math.sin(x)*maxheight); } }