Patti
Posts: 46
Nickname: patti
Registered: Feb, 2002
|
|
Re: What is wrong with my start method?
|
Posted: Mar 13, 2002 6:37 PM
|
|
Here it is. It's just not picking up the very last offset. I've tried everything-maybe static is preventing it. I don't know. I don't really understand the difference in static or not static yet. That's one of those things that hasn't sunk in. The other is the difference in public and private-well I sort of understand that a little. Thanks for help.
import java.applet.Applet;
import java.awt.*;
// An applet to perform a simple animation.
public class Drive extends Applet{
private Graphics page;
//sets up the animation.
public void init() {
setVisible (true);
setSize (450,250);
page = getGraphics();
page.setXORMode (getBackground());
}//method init
public void start(){
Car.drive(page);
}//method start
}//class Drive
//Represents the car that moves across the screen.
class Car {
private final static int MOVE = 2;
private final static int RIGHT_SIDE = 450;
private final static int NUM_POINTS = 10;
private final static int PAUSE = 1000000;
private static int[] car_x = {80,70,70,90,95,140,150,175,180,170};
private static int[] car_y = {190,190,170,170,155,155,170,170,190,190};
private static int [] car_x_update = new int [NUM_POINTS];
//Performs the animation
public static void drive (Graphics page) {
//Loop until car drives off the right side.
for (int offset=1; offset < RIGHT_SIDE; offset += MOVE) {
draw_car (offset,page); //draw the car
for (int pause=1; pause < PAUSE; pause++);
draw_car (offset,page); //erase the car
}
}//method drive
//Draws the car at a particular x offset.
public static void draw_car (int offset, Graphics page) {
page.setColor (Color.red);
page.drawPolyline (car_x, car_y,10);//car
page.drawArc (80+offset,180,20,20,0,180);//rear wheel well
page.drawArc (150+offset,180,20,20,0,180);//front wheel well
page.drawLine (100+offset,190,150+offset,190);
page.setColor (Color.black);
page.drawOval (83+offset,183,14,14);//rear wheel
page.drawOval (153+offset,183,14,14); //front wheel
page.drawLine (81+offset,170,81+offset,150);//antenna
//Update the x coordinates.
for (int scan=0; scan < NUM_POINTS; scan++)
car_x_update[scan] = car_x[scan] + offset;
}//method draw_car
} //class Car
|
|