// Name: Whitaker Brand // TA: Isaac // Course: CSE142 // Quarter: 17au // This is an example usage of DrawingPanel to draw a Car. // // Draws multiple cars, using a parameterized method to control // the location of the car. // // NOTE: the implementation of this car isn't that great, // because it doesn't let us change the size of the // car. Check out Car3.java for an improved version. import java.awt.*; public class Car2 { public static void main(String[] args) { DrawingPanel drawPanel = new DrawingPanel(700, 1000); // width, height drawPanel.setBackground(Color.LIGHT_GRAY); Graphics pen = drawPanel.getGraphics(); drawCar(pen, 10, 100); for (int i = 1; i <= 4; i++) { drawCar(pen, 300, 100 + (i * 200)); } } // Uses the given Graphics object to draw a car at the location given // by x and y. x and y represent the top-left point of the car. public static void drawCar(Graphics g, int x, int y) { // NOTE: the implementation of this car isn't that great, // because it doesn't let us change the size of the // car. Check out Car3.java for an improved version. // assure that the color is black, and draw the body // and the tires g.setColor(Color.BLACK); g.fillRect(x, y, 200, 100); g.fillOval(x + 10, y + 70, 60, 60); g.fillOval(x + 130, y + 70, 60, 60); g.setColor(Color.BLUE); g.fillRect(x + 130, y + 20, 70, 40); g.setColor(Color.RED); g.fillRect(x, y + 40, 100, 10); } }