import java.awt.*;
import java.applet.*;

public class helloWorld extends Applet implements Runnable {
	Thread animationThread=null;
	protected int cur = 0, delay=150;
	protected Image frame[] = new Image[10];

/* 1 */
	protected String dir = "waving";
	public void init() {
		resize(150,150);
/* 2 */
		String iTemp = getParameter("INDEX");
		if ( iTemp != null && Integer.valueOf(iTemp).intValue() == 1)
			dir = "tumbling";
		for (int i = 0; i<10; i++) 
		   frame[i] = getImage(getDocumentBase(),dir+"/T"+i+".gif");
	}

	public void start() {
		animationThread = new Thread(this);    // Spawn Animation thread
		animationThread.start();
	}

	public void run() {
		while (true) {
			for (cur=1; cur<10; cur++) {
				repaint();
				try { // slow down the image changes
                        		Thread.sleep(delay);
                        	} catch (InterruptedException e) {}
			}
			cur=0;
			repaint();
		}
	}

/* 3 */

	public void paint(Graphics g) {
		g.drawString(new String("Hello World!"), 70,50);
		g.drawImage(frame[cur], 25, 55, this);
	}
	
	public void stop() {
		if (animationThread != null && animationThread.isAlive())
			animationThread.stop();
	}
}
