一个j2me的小问题,多给分
package org.javame.chapter7;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ThreadAnimation extends MIDlet {
Display dis;
ThreadAnimationCanvas tac=new ThreadAnimationCanvas();
public ThreadAnimation() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
dis.setCurrent(tac);
}
class ThreadAnimationCanvas extends Canvas implements Runnable{
boolean stopFlag=false;
private int canW,canH;
private static final int LEN=8;
private int curIndex=0;
private Image[] imgList;
public ThreadAnimationCanvas(){
try{
imgList=new Image[LEN];
for(int i=0;i<LEN;i++){
imgList[i]=Image.createImage("/image"+i+".jpg");
System.out.println("image"+i+".jpg has been loaded");
}
}catch(Exception e){
System.out.println("Can not load images:"+e);
}
canW=this.getWidth();
canH=this.getHeight();
System.out.println("canvas width is "+canW);
System.out.println("canvas height is "+canH);
new Thread(this).start();
}
public void run(){
while(!stopFlag){
curIndex++;
if(curIndex==LEN-1){ //请问这个if语句什么意思
curIndex=-2;
}
try{
repaint();
Thread.sleep(100);
}catch(Exception e){}
}
}
public void paint(Graphics g){
g.setColor(0x000000);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
int w,h,x,y;
if(curIndex>=0 && imgList[curIndex]!=null){
w=imgList[curIndex].getWidth();
h=imgList[curIndex].getHeight();
x=(canW-w)/2;
y=(canH-h)/2;
g.drawImage(imgList[curIndex], x, y, Graphics.LEFT|Graphics.TOP);
}
}
}
}