Image pImg[]; 的用法。(skyyoung(路人甲))

jspxnet 2002-01-31 04:54:29
Image pImg[]; 的用法。


------------------------------------------------------------
不是
int[] pixels = new int[width * height]; 图片点的用法
...全文
65 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyyoung 2002-01-31
  • 打赏
  • 举报
回复
Do simple animation using Images
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();
}
}
}
}
}


jspxnet 2002-01-31
  • 打赏
  • 举报
回复
你没有错,我也没有错。
byte[] pixels = new byte[width * height]; //图片点阵数组
-----------------------------------------------
Image pImg[]; 图片数组
如:
pImg[1] = image1;
pImg[2] = image2;




62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧