// Improves the van drawing program by creating a parameterized method // to draw a van at any location. // // You must download DrawingPanel.java from the course website and save it // in the same folder as this file to run this program. import java.awt.*; public class Drawing2 { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(400, 200); panel.setBackground(Color.LIGHT_GRAY); Graphics brush = panel.getGraphics(); drawVan(brush, 10, 30); drawVan(brush, 150, 10); drawVan(brush, 10, 130); } // draw a single van // // Graphics pen - the Graphics object to use when drawing // int x - the x-coordinate of the van's upper-left corner // int y - the y-coordinate of the van's upper-left corner public static void drawVan(Graphics pen, int x, int y) { // draw body pen.setColor(Color.BLACK); pen.fillRect(x, y, 100, 50); // draw wheels pen.setColor(Color.RED); pen.fillOval(x + 10, y + 40, 20, 20); pen.fillOval(x + 70, y + 40, 20, 20); // draw windshield pen.setColor(Color.CYAN); pen.fillRect(x + 70, y + 10, 30, 20); } }