import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
public class SchoolView extends GameCanvas implements Runnable {
private Display dis;
// 循环显示用的图片数组
private Image img[] = new Image[4];
private int i = 0;
// 判断循环是否仍在运行
private boolean isPlay;
private Graphics g = getGraphics();
public SchoolView(Display display) {
super(true);
dis = display;
try {
img[0] = Image.createImage("/quanjing_1.png");
img[1] = Image.createImage("/tushuguan1.png");
img[2] = Image.createImage("/yundonghui1.png");
img[3] = Image.createImage("/shitou1.png");
} catch (Exception e) {
System.out.println("导入图片错误");
}
start();
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}
public void run() {
while (isPlay) {
draw(g);
if (i >3) {
i = 0;
}
i++;
try {
Thread.sleep(1500);
} catch (Exception e) {
}
}
}
public void draw(Graphics g) {
System.out.println("ddddddddddddddddddddddddd");
g.setColor(0);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img[i], (getWidth() - img[i].getWidth()) / 2, (getHeight() - img[i].getHeight()) / 2, 0);
flushGraphics();
}
}
N个图片的轮回显示j2me
最新推荐文章于 2021-05-28 22:29:53 发布