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

📄 mygame.java

📁 基于JAVA的手机程序入门
💻 JAVA
字号:
package lyp.game;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class myGame extends MIDlet implements CommandListener,ItemCommandListener{

	static gameCanvas myCanvas;
	private Command exitCommand;
	private Command pauseCommand,okCommand;
	private Command starCommand,backCommand;
	private Form mainForm;
	private List setList;
	private Alert alert;
	private StringItem item1,item2,item3;
	private String speed[]={
			"0","1","2","3","4","5","6"
	};
	
	static gameover go;
	static Display display;
	
	
	
	public myGame() {
		
		exitCommand=new Command("exit",Command.EXIT,1);
		pauseCommand=new Command("pause",Command.STOP,2);
		starCommand=new Command("star",Command.OK,2);
		okCommand=new Command("ok",Command.OK,2);
		backCommand=new Command("back",Command.OK,1);
		go=new gameover();
		
		setList=new List("游戏速度",Choice.IMPLICIT,speed,null);
		setList.addCommand(backCommand);
		setList.setCommandListener(this);
		
		alert=new Alert("关于:","本游戏仅用于学习--作者:卢研平",null,AlertType.INFO);
		
		mainForm=new Form("welecom");
		item1=new StringItem("","开始",Item.BUTTON);
		item1.setDefaultCommand(okCommand);
		item1.setItemCommandListener(this);
		mainForm.append(item1);
		item2=new StringItem("","设置",Item.BUTTON);
		item2.setDefaultCommand(okCommand);
		item2.setItemCommandListener(this);
		mainForm.append(item2);
		item3=new StringItem("","关于",Item.BUTTON);
		item3.setDefaultCommand(okCommand);
		item3.setItemCommandListener(this);
		mainForm.append(item3);
		
		go.addCommand(okCommand);
		go.addCommand(exitCommand);
		go.setCommandListener(this);
		display=Display.getDisplay(this);
		display.setCurrent(mainForm);
		
		block.step=0;
		
	}

	protected void startApp() throws MIDletStateChangeException {
		
		
		
	}

	protected void pauseApp() {

	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

	}

	public void commandAction(Command arg0, Displayable arg1) {
		
		if (arg0 == exitCommand) {
			try {
				destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
			notifyDestroyed();
		}
		if (arg0 == pauseCommand) {
			myCanvas.removeCommand(pauseCommand);
			myCanvas.addCommand(starCommand);
			pauseApp();
			notifyPaused();
		}
		if (arg0 == starCommand) {
			myCanvas.removeCommand(starCommand);
			myCanvas.addCommand(pauseCommand);
			try {
				startApp();
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
		if(arg0==okCommand)
		{
			gameCanvas.mymap=null;
			gameCanvas.myblock=null;
			myCanvas=null;
			display.setCurrent(mainForm);
		}
		if(arg0==backCommand)
		{
			display.setCurrent(mainForm);
		}
		if(arg1.equals(setList))
		{
			if(arg0==List.SELECT_COMMAND)
			{
				switch(((List)arg1).getSelectedIndex())
				{
				case 0:
					block.step=0;
					break;
				case 1:
					block.step=1;
					break;
				case 2:
					block.step=2;
					break;
				case 3:
					block.step=3;
					break;
				case 4:
					block.step=4;
					break;
				case 5:
					block.step=5;
					break;
				case 6:
					block.step=6;
					break;
				}
				display.setCurrent(mainForm);	
			}
		}
	}

	public void commandAction(Command arg0, Item arg1) {
		if(arg1==item1)
		{
			if(arg0==okCommand)
			{
				myCanvas=new gameCanvas();
				myCanvas.addCommand(exitCommand);
				myCanvas.addCommand(pauseCommand);
				myCanvas.setCommandListener(this);
				display.setCurrent(myCanvas);
			}
		}
		if(arg1==item2)
		{
			if(arg0==okCommand)
			{
				display.setCurrent(setList);
			}
		}
		if(arg1==item3)
		{
			if(arg0==okCommand)
			{
				display.setCurrent(alert,mainForm);
				alert.setTimeout(Alert.FOREVER);
			}
		}
		
	}

}




⌨️ 快捷键说明

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