⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainmidlet.java

📁 JME贪食蛇游戏,初学jme作品,不好不要见怪
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -