pingbao.java

来自「J2EE的无线手机通讯运用软件」· Java 代码 · 共 59 行

JAVA
59
字号


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class pingbao extends Canvas implements Runnable{
     Image[] frames;
     int left,top;
     boolean alive;
     int interval;
     int currentFrame;
     int numFrames;
     MIDlet midlet;
     Thread thread;

 pingbao(MIDlet midlet,Image[] frames,int left,int top,int interval){
        this.frames=frames;
        this.left=left;
        this.interval=interval;
        this.alive=true;
        this.currentFrame=0;
        this.numFrames=frames.length;
        this.midlet=midlet;
        thread=new Thread(this);
        thread.start();
 }

     public pingbao(MIDlet midlet,Image[] frames,int interval){
        this(midlet,frames,0,0,interval);
        this.left=(this.getWidth()-frames[0].getWidth())/2;
        this.top=(this.getHeight()-frames[0].getHeight())/2;
     }
     public void paint(Graphics g){
        g.setColor(0x000000);
        g.fillRect(0,0,getWidth(),getHeight());
        g.drawImage(frames[currentFrame++],left,top,Graphics.LEFT|Graphics.TOP);
        if(currentFrame>=numFrames){
            currentFrame=0;
        }
      }
     public void keyPressed(int keyCode){
        if(getGameAction(keyCode)==FIRE){
            alive=!alive;
         }else{
                thread=null;
              ((Move)midlet).exit();  
               }
     }
     public void run(){
        while(true){
            if(alive){
                 repaint();
                try{
                    Thread.sleep(interval);
                }catch(InterruptedException e){
                }
             }
         }
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?