// CSE 142 Lecture 6 // More Parameters, Graphics import java.awt.*; // (to use Graphics and Color) // Draws a bunch of boxy looking cars // Demonstrates the process we went through of adding // a single parameter at a time when parameterizing // the drawCar method. public class DrawCar { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(260, 160); panel.setBackground(Color.LIGHT_GRAY); Graphics g = panel.getGraphics(); drawCar(g, 10, 30, 100); drawCar(g, 150, 20, 50); // Bumper to bumper cars for (int i = 0; i < 10; i++) { drawCar(g, i * 35 + 10, 120, 30); } } // Draws a single car at (10, 30) that is 100 pixels wide public static void drawCarStatic(Graphics g) { // body // This was the ugly green color we picked for the car's body Color c = new Color(20, 210, 100); g.setColor(c); g.fillRect(10, 30, 100, 50); // wheels g.setColor(Color.RED); g.fillOval(20, 70, 20, 20); g.fillOval(80, 70, 20, 20); // windshield g.setColor(Color.CYAN); g.fillRect(80, 40, 30, 20); } // Draws a single car at (x, y) that is 100 pixels wide public static void drawCarTranslate(Graphics g, int x, int y) { // body // This was the ugly green color we picked for the car's body Color c = new Color(20, 210, 100); g.setColor(c); g.fillRect(x, y, 100, 50); // wheels g.setColor(Color.RED); g.fillOval(x + 10, y + 40, 20, 20); g.fillOval(x + 70, y + 40, 20, 20); // windshield g.setColor(Color.CYAN); g.fillRect(x + 70, y + 10, 30, 20); } // Draws a single car at (x, y) that is size pixels wide public static void drawCar(Graphics g, int x, int y, int size) { // body // This was the ugly green color we picked for the car's body Color c = new Color(20, 210, 100); g.setColor(c); g.fillRect(x, y, size, size / 2); // wheels g.setColor(Color.RED); g.fillOval(x + size / 10, y + 2 * size / 5, size / 5, size / 5); g.fillOval(x + 7 * size / 10, y + 2 * size / 5, size / 5, size / 5); // windshield g.setColor(Color.CYAN); g.fillRect(x + 7 * size / 10, y + size / 10, 3 * size / 10, size / 5); } }