I am working on an animated stick figure that walks across the applet screen. I was advised by someone in the New to Java Forum to post in the Swing forum for better direction with my problem. I am fairly new to Java and Swing and can use some help. I can get the stick figure to walk across the screen, but I can't seem to get the leg to go in the same direction as the body. The walking leg doesn't keep moving forward with the body. Instead, it just seems to keep stretching like the end of the leg is stuck in one spot. I know it has to do with that particular point, but I can't seem to get it to increment with the rest of the body. Can anyone give any advice on what I actually need to do to get the leg walking in the same increment as the body? Thank you in advance for any help that can be provided. Code is below...
import java.applet.*;*
*import java.awt.*;
import javax.swing.*;
public class Walkers extends Applet //implements Runnable
{
private static final long serialVersionUID = 1L;
private int body = 85; //set horizontal body location
private int leg1 = 125;
private int leg2 = 155;
private int index = 0;
//private int[] vert = {310,310};
private int[] horiz = {leg1,leg2};
private int oval = 30;
private int rightarm = 40;//right arm position
private int leftarm = 140;//left arm position
private int step = 25;
private int incremoval = oval+step;//increment the head oval across the screen
private int LIMIT = 800;
private final int SLEEP_TIME = 400;
public void start()
{
index = 0;
}
public void paint(Graphics gr)
{
gr.setColor(Color.WHITE);
gr.drawOval(oval,30,85,80);
gr.drawLine(body,110,body,310);
gr.drawLine(body,140,rightarm,160);
gr.drawLine(body,140,leftarm,160);
oval = oval + step;
body = body + step;
rightarm = rightarm + step;
leftarm = leftarm + step;
gr.setColor(Color.BLACK);
gr.drawOval(oval,30,85,80);
gr.drawLine(body,110,body,310);
gr.drawLine(body,140,rightarm,160);
gr.drawLine(body,140,leftarm,160);
gr.drawLine(body,210,horiz[index],310);
horiz = horiz+step;
++index;
if(index ==horiz.length)
index = 0;
try
{
Thread.sleep(SLEEP_TIME);
}
catch(InterruptedException e)
{
}
if (body < LIMIT)
repaint();
}
}