// CSE 142, Winter 2007 // Author: Marty Stepp // // This program draws several cars at different positions and sizes. import java.awt.*; public class DrawCars { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(300, 200); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); drawCar(g, 10, 30, 100); drawCar(g, 150, 10, 50); drawCar(g, 40, 80, 200); } // Draws a car figure at the given position and size. public static void drawCar(Graphics g, int x, int y, int size) { g.setColor(Color.BLACK); g.fillRect(x, y, size, size / 2); // wheels g.setColor(Color.RED); g.fillOval(x + size / 10, y + size * 4 / 10, size / 5, size / 5); g.fillOval(x + size * 7 / 10, y + size * 4 / 10, size / 5, size / 5); // windshield g.setColor(Color.CYAN); g.fillRect(x + size * 7 / 10, y + size / 10, size * 3 / 10, size / 5); } }