I need this to move across the screen. Can anyone help?
This is an assignment for school, and I can't use any methods from the polygon class. I think I need to change the array values, but not quite sure how to go about it.
Here is the code:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
public class Truck1 extends
Applet {
private final int APPLET_WIDTH = 400;
private final int APPLET_HEIGHT = 400;
private final int DELAY = 20;
private Timer timer;
public int[] xStart = {15, 15, 15, 15, 15, 68, 70, 72, 75, 77,
80, 80, 80, 67, 64, 64, 64, 39, 19, 15};
public int[] yStart = {8, 70, 73, 75, 77, 77, 77, 77, 77, 77, 77,
55, 33, 33, 33, 20, 8, 8, 8, 8};
public int[] xMove = {20, 20, 20, 20, 20, 73, 75, 77, 80, 82,
85, 85, 85, 72, 69, 69, 69, 44, 24, 20};
public int[] yMove = {13, 75, 78, 80, 82, 82, 82, 82, 82, 82, 82,
60, 38, 38, 38, 25, 13, 13, 13, 13};
//===============================================================
public void init()
{
timer = new Timer (DELAY, new ReboundActionListener());
timer.start();
setBackground (Color.white);
setSize (APPLET_WIDTH, APPLET_HEIGHT);
}
//===============================================================
public void paint (Graphics page)
{
page.setColor (Color.red);
page.fillPolygon (xStart, yStart, xStart.length);
page.fillPolygon (xMove, yMove, xMove.length);
page.fillOval(25, 77, 25, 25); //left tire
page.fillOval(55, 77, 25, 25); //right tire
page.setColor(Color.white);
page.fillOval(30, 85, 10, 10); //center of left tire
page.fillOval(60, 85, 10, 10); //center of right tire
}
//=============================================================
private class ReboundActionListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
repaint();
}
}
}