// CSE 142, Autumn 2010 // Author: Marty Stepp // This program draws "car" figures. // It is a demonstration of graphics with methods and parameters. import java.awt.*; public class Car { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 300); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); drawCar(g, 10, 30); drawCar(g, 200, 18); drawCar(g, 80, 178); } // Draws a car using the given pen at the given (x, y) 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); } }