你没有错,我也没有错。
byte[] pixels = new byte[width * height]; //图片点阵数组
-----------------------------------------------
Image pImg[]; 图片数组
如:
pImg[1] = image1;
pImg[2] = image2;
byte[] pixels = new byte[width * height]; //图片点阵数组
-----------------------------------------------
Image pImg[]; 图片数组
如:
pImg[1] = image1;
pImg[2] = image2;
By using a Thread, we switch between 2 GIFs ( and ) import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.net.*;public class Animation extends Applet {
Image [] img;
int index = 0;
int maxImg;
MediaTracker tracker; public void init() {
img = new Image[2]; // 2 images in animation
maxImg = img.length - 1;
tracker = new MediaTracker(this);
try {
// images loading
img[0] = getImage(new URL(getDocumentBase(), "gumby.gif"));
img[1] = getImage(new URL(getDocumentBase(), "gumby2.gif"));
tracker.addImage(img[0],0);
tracker.addImage(img[1],1);
tracker.waitForAll();
}
catch (Exception e) {
e.printStackTrace();
} AnimationThread at = new AnimationThread();
at.delayedAnimation(this, 500);
at.start();
} public void paint(Graphics g) {
if (img[0] != null) {
g.drawImage(img[index],0,0,this);
index = (index < maxImg) ? index + 1 : 0;
}
} public void animate() {
repaint();
} class AnimationThread extends Thread {
Animation animationApplet;
int delay; public void delayedAnimation(Animation a, int delay) {
this.animationApplet = a;
this.delay = delay;
} public void run() {
while (true) {
try {
sleep(delay);
animationApplet.animate();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
}