How do I achieve animation in the web?
.
Import java.applet. *;
Import java.awt. *;
Public class Animapplet Extends
Applet imports runnable {
Image [] images = new image [2];
INT frame = 0;
Thread thread;
Public void init () {
Images [0] = GetImage (GetDocumentBase (),
"http://hostname/image0.gif");
Images [1] = getImage (getDocumentBase (),
"http://hostname/image1.gif");
}
Public void start () {
"thread = new thread (this)). START ();
}
Public void stop () {
thread = null;
}
Public void paint (graphics g) {
G.DrawImage (images [frame], 0, 0, this);
}
Public void run () {
INT delay = 1000; // 1 second
Try {
While (thread == thread.currentthread ()) {
Frame = (Frame 1)% images.Length;
Repaint ();
Thread.sleep (delay);
}
} catch (exception e) {
}
}
}
End!