Java Example Program / Sample Source Code
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
public class AnimateArrayOfImages extends Applet implements Runnable {
Thread thread;
Image[] images = new Image[2];
int value = 0;
public void init() {
images[0] = getImage(getDocumentBase(), "http://domain/image1.gif");
images[1] = getImage(getDocumentBase(), "http://domain/image2.gif");
thread = new Thread(this);
thread.start();
}
public void run() {
try {
while (thread == Thread.currentThread()) {
value = (value + 1) % images.length;
repaint();
Thread.sleep(1500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawImage(images[value], 0, 0, this);
}
} |
|
|