import java.awt.*; import java.applet.*; /* */ public class MovingCircle extends BasicAnimationApplet { int x, y; // the position of the circle int vx; // the horizontal velocity public void init() { x = 0; y = 50; vx = 4; } public void step() { int width = getSize().width; // width of applet window x += vx; if (x > width) { // wrap around vx = -vx; x = width; } if (x < 0) { vx = -vx; x = 0; } } public void paint(Graphics g) { int size = 20; g.fillOval(x, y, size, size); } }