mainmidlet.java
来自「JME贪食蛇游戏,初学jme作品,不好不要见怪」· Java 代码 · 共 59 行
JAVA
59 行
package Src;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet implements CommandListener,ItemStateListener{
protected VectorCanvas gameframe;
protected Display d;
private Command exitCommand;
private Command runCommand;
private Gauge gameLvl;
protected Form form;
private StringItem myString;
public MainMidlet() {
d=Display.getDisplay(this);
myString=new StringItem("当前的游戏难度:","1");
form=new Form("贪食蛇");
gameLvl=new Gauge("难度选择",true,5,1);
gameLvl.setLayout(Item.LAYOUT_CENTER);
form.append(new Spacer(50,80));
form.append(gameLvl);
form.append(myString);
form.setItemStateListener(this);
exitCommand=new Command("退出",Command.EXIT,1);
runCommand=new Command("前进",Command.SCREEN,1);
form.addCommand(exitCommand);
form.addCommand(runCommand);
form.setCommandListener(this);
d.setCurrent(form);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
}
public void exit(){
System.gc();
this.notifyDestroyed();
}
public void commandAction(Command arg0, Displayable arg1) {
if(arg0==exitCommand){
exit();
}
if(arg0==runCommand){
gameframe =new VectorCanvas(this);
d.setCurrent(gameframe);
}
}
public void itemStateChanged(Item arg0) {
if(arg0==gameLvl)
{
VectorCanvas.SLEEP_TIME=300-gameLvl.getValue()*50;
myString.setText(""+gameLvl.getValue());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?