📄 pingbao.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -