Unlucky4Ever
Technical User
I need this ASAP!
I need to know how to animate this...
There is the entire code, and I want to make the cars move left off of the screen.
I need to know how to animate this...
Code:
// This program draws a pentagon with the <drawPolygon> method.
// Methods <drawPolygon> and <fillPolygon> take a Polygon object as
// parameter. The polygon object stores a set of points. Points can
// be added to a Polygon object with the <addPoint> method.
import java.awt.*;
import java.applet.*;
public class Example1 extends Applet
{
public void paint(Graphics g)
{
//road
g.setColor(Color.gray);
g.fillRect(0,620,1050,620);
g.setColor(Color.yellow);
g.drawLine(0,650,1050,650);
g.setColor(Color.black);
g.drawLine(0,675,1050,675);
//sky
g.setColor(Color.blue);
g.drawRect(0,0,1050,100);
g.fillRect(0,0,1050,100);
g.setColor(Color.gray);
g.fillOval(325,85,50,50);
g.fillOval(350,75,85,70);
g.fillOval(410,85,50,50);
g.fillOval(525,45,50,50);
g.fillOval(550,35,85,70);
g.fillOval(610,45,50,50);
g.fillOval(725,75,50,50);
g.fillOval(750,65,85,70);
g.fillOval(810,75,50,50);
//sun
g.setColor(Color.orange);
g.fillOval(-30,-30,185,185);
g.drawLine(200,20,230,45);
//car1
g.setColor(Color.darkGray);
g.fillRect(590,600,40,20);
Polygon penta = new Polygon();
g.setColor(Color.blue);
penta.addPoint(600,540);
penta.addPoint(940,540);
penta.addPoint(940,540);
penta.addPoint(980,580);
penta.addPoint(980,620);
penta.addPoint(620,620);
penta.addPoint(600,600);
penta.addPoint(600,540);
g.fillPolygon(penta);
g.setColor(Color.yellow);
g.fillRect(600,540,30,20);
//windsheild1
Polygon wind = new Polygon();
wind.addPoint(680,540);
wind.addPoint(700,470);
wind.addPoint(720,470);
wind.addPoint(700,540);
g.setColor(Color.lightGray);
g.fillPolygon(wind);
//wheel1
g.drawPolygon(penta);
g.setColor(Color.black);
penta.addPoint(680,640);
penta.addPoint(740,480);
penta.addPoint(740,540);
//rim/tire1
g.setColor(Color.black);
g.fillOval(660, 580, 80, 80);
g.setColor(Color.yellow);
g.fillOval(670, 590, 60, 60);
//rim/tire2
g.setColor(Color.black);
g.fillOval(880, 580, 80, 80);
g.setColor(Color.yellow);
g.fillOval(890, 590, 60, 60);
//car2
g.setColor(Color.darkGray);
g.fillRect(190,600,40,20);
Polygon penta1 = new Polygon();
g.setColor(Color.blue);
penta1.addPoint(100,540);
penta1.addPoint(440,540);
penta1.addPoint(440,540);
penta1.addPoint(480,580);
penta1.addPoint(480,620);
penta1.addPoint(120,620);
penta1.addPoint(100,600);
penta1.addPoint(100,540);
g.fillPolygon(penta1);
g.setColor(Color.yellow);
g.fillRect(100,540,30,20);
g.setColor(Color.lightGray);
//wheel2
g.drawPolygon(penta);
g.setColor(Color.black);
penta.addPoint(180,640);
penta.addPoint(240,480);
penta.addPoint(240,540);
//rim/tire2
g.setColor(Color.black);
g.fillOval(160, 580, 80, 80);
g.setColor(Color.yellow);
g.fillOval(170, 590, 60, 60);
//rim/tire2
g.setColor(Color.black);
g.fillOval(380, 580, 80, 80);
g.setColor(Color.yellow);
g.fillOval(390, 590, 60, 60);
}
}
There is the entire code, and I want to make the cars move left off of the screen.