// This variation of the Car program uses a parameterized method to draw two // different cars on a DrawingPanel. Both cars are of the same size, but their // positions are different. import java.awt.*; public class Car2 { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 200); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); drawCar(g, 10, 30); drawCar(g, 150, 10); } // Draws a car figure using the given Graphics object with upper-left // corner (x, y) 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); } }