import java.awt.*; public class Motion { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(500, 200); Graphics g = p.getGraphics(); for (int i = 0; i < 100; i++) { // Color the whole DrawingPanel white g.setColor(Color.WHITE); g.fillRect(0, 0, 500, 200); // Make the red circle // It moves to the right by 5 pixels every time through the loop // It moves up and down in a sine wave g.setColor(Color.RED); g.drawOval(i * 5, (int)(Math.sin(i / (100 / (Math.PI * 4))) * 95) + 95, 10, 10); // Pause the panel so that we can see each frame p.sleep(50); } } }