// This program draws a rudimentary van using DrawingPanel. // // DEVELOPMENT NOTES: // (These notes would not be in your program's comments. They are here // to help you understand important topics or elements of this code.) // // Further improves the van drawing program by adding a parameter for // the van's size to the drawVan method. Notice how both the size // of the van and the offsets for the components depend on the size. // // 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 Drawing3 { 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, 100); drawVan(brush, 150, 10, 50); for (int i = 0; i < 5; i++) { drawVan(brush, 10 + 50 * i, 130, 40); } } // 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 // int size - the size (width) of the van public static void drawVan(Graphics pen, int x, int y, int size) { // draw body pen.setColor(Color.BLACK); pen.fillRect(x, y, size, size / 2); // draw windshield pen.setColor(Color.CYAN); pen.fillRect(x + (size * 7 / 10), y + (size / 10), size * 3 / 10, size / 5); // draw wheels pen.setColor(Color.RED); pen.fillOval(x + (size / 10), y + (size * 4 / 10), size / 5, size / 5); pen.fillOval(x + (size * 7 / 10), y + (size * 4 / 10), size / 5, size / 5); } }