// This program draws several car figures onto a DrawingPanel. import java.awt.*; public class Car { public static void main(String[] args) { // create the window and get the pen to draw DrawingPanel panel = new DrawingPanel(400, 300); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); // draw three cars drawCar(g, 10, 30); drawCar(g, 150, 70); drawCar(g, 50, 220); } // draws one car figure with its top/left corner at the given position 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); } }