New to Applets..How do you draw the figure in the paint method multiple times?
My code draws one car, but I wanted to have six cars....I know I can copy this 6 times, but is there a more efficient way?
I want to be able to set the position of each car as well...
Code:
public class DrawCar extends Applet
{
public void paint(Graphics g)
{ Graphics2D g2 = (Graphics2D)g; // create the car body
Rectangle body = new Rectangle(10, 110, 60, 10);
// create the car tires
Ellipse2D.Double frontTire = new Ellipse2D.Double(20, 120, 10, 10);
Ellipse2D.Double rearTire = new Ellipse2D.Double(50, 120, 10, 10); // create the 4 points connecting the windshields and roof
Point2D.Double r1 = new Point2D.Double(20, 110);
Point2D.Double r2 = new Point2D.Double(30, 100);
Point2D.Double r3 = new Point2D.Double(50, 100);
Point2D.Double r4 = new Point2D.Double(60, 110); // create the windshields and roof of the car
Line2D.Double frontWindshield = new Line2D.Double(r1, r2);
Line2D.Double roofTop = new Line2D.Double(r2, r3);
Line2D.Double rearWindshield = new Line2D.Double(r3, r4); // draw all of the car parts on the screen
g2.draw(body);
g2.draw(frontTire);
g2.draw(rearTire);
g2.draw(frontWindshield);
g2.draw(roofTop);
g2.draw(rearWindshield);
} // end of paint
}
// end of CarDrawer*/