// CSE 142, Summer 2008 (Marty Stepp) // This program draws several car figures at different positions // and sizes using parameters. import java.awt.*; public class Cars { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(600, 500); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); // draw 3 cars drawCar(g, 10, 10, 100); drawCar(g, 130, 40, 50); drawCar(g, 270, 90, 200); // draw a line of cars for (int i = 0; i < 10; i++) { drawCar(g, i * 60, 300, 50); } } public static void drawCar(Graphics g, int x, int y, int size) { // assumes that the car's T/L corner is (10, 30) // assumes that the car's size is 100 g.setColor(Color.BLACK); g.fillRect(x, y, size, size / 2); g.setColor(Color.RED); g.fillOval(x + size / 10, y + size * 2 / 5, size / 5, size / 5); g.fillOval(x + size * 7 / 10, y + size * 2 / 5, size / 5, size / 5); g.setColor(Color.CYAN); g.fillRect(x + size * 7 / 10, y + size / 10, size * 3/10, size / 5); } }