Basic steps achieved by animated applet

zhaozj2021-02-17  56

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!

转载请注明原文地址:https://www.9cbs.com/read-29961.html

New Post(0)