// CSE 142 Autumn 2007, Marty Stepp // This program draws two car figures at different sizes and positions. import java.awt.*; // so I can use Graphics public class DrawCar2 { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(600, 400); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); // g x y size drawCar(g, 10, 30, 100); drawCar(g, 150, 10, 50); // draw lots of cars at different x/y positions for (int i = 0; i < 10; i++) { drawCar(g, 40 + 50*i, 150, 30); } } // This method draws one car figure with 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); g.setColor(Color.RED); g.fillOval(x + size / 10, y + 2 * size / 5, size / 5, size / 5); g.fillOval(x + 7 * size / 10, y + 2 * size / 5, size / 5, size / 5); g.setColor(Color.CYAN); g.fillRect(x + 7 * size / 10, y + size / 10, 3 * size / 10, size / 5); } }