import java.awt.*; public class AnimatedCar { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(260, 100); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); for (int x = 0; x < 100; x++) { panel.clear(); drawCar(g, x, 30); panel.sleep(50); } } // Draws a car at the given (x, y) location. public static void drawCar(Graphics g, int x, int y) { g.setColor(Color.BLACK); g.fillRect(x, y, 100, 50); g.setColor(Color.RED); g.fillOval(x + 10, y + 40, 20, 20); g.fillOval(x + 70, y + 40, 20, 20); g.setColor(Color.CYAN); g.fillRect(x + 70, y + 10, 30, 20); } }