I'm trying to run basic animations, and all of the problems in my program is rooted in one of my loops running twice instead of once. I've isolated the problem here:
import java.awt.*;
import java.applet.*;
public class PrinnyTest extends Applet{
public void init()
{
setSize(600, 550);
}
public void paint (Graphics g)
{
Image img = getImage(getDocumentBase(), "http://www.clipartqueen.com/image-files/cats-head.png");
for(int y = 600;y>=20; y--)
{
g.setColor(Color.white);
g.fillRect(0, 0, 600, 550);
g.drawImage(img, 40, y, null);
try
{
Thread.sleep(20);
}
catch(InterruptedException ie)
{}
}
}
}
As you can see, it moves the image to the top but then resets the position and starts the loop over again. I feel like the answer is staring me right in the face, but for some reason I can't figure it out. Any help would be greatly appreciated.