// Marty Stepp, CSE 142, Autumn 2008 // This program draws two "car" figures using parameters to control the // x/y position and size of each one. import java.awt.*; public class Car { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(300, 200); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); // x y size drawCar(g, 10, 30, 100); drawCar(g, 150, 75, 50); } // Draws a car figure using the given pen, at the given x/y 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 + size * 4 / 10, size / 5, size / 5); g.fillOval(x + size * 7 / 10, y + size * 4 / 10, size / 5, size / 5); g.setColor(Color.CYAN); g.fillRect(x + size * 7 / 10, y + size / 10, size * 3 / 10, size / 5); } }