Image probe;
Thread t;
public int x=410,y=250;
public void init()
{
//Images Call
probe = getImage(getDocumentBase(),"image/probe.png");
t = new Thread();
}
public void paint(Graphics g)
{
for(int i=0;i<5;i++)
{
g.drawImage(probe,x,y,50,50,this);
g.setColor(Color.red);
System.out.print(i);
x=x+10;
y=y+10;
repaint();
try
{
t.sleep(100);
} catch(Exception e) {}
}
}
So in this it should do my for loop 5 times correct? but instead it does it over and over and over and never stops when i want it to just move 5 times then stop, but instead it just goes on forever.
If your loop is in the
paint()method and you callrepaint()from within the loop you will cause the method to be called continually! You loop isn’t executing over and over, it’s executing once and then calling itself to be called again.