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

📄 sharecommand.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

	public class ShareCommand extends MIDlet implements CommandListener {

		private Command exitCommand,listCommand;
		private TextBox tb;
		private List mainList;
		Display display;

		public ShareCommand() {
			exitCommand = new Command("Exit", Command.EXIT, 1);
			listCommand = new Command("List", Command.SCREEN, 1);
			tb = new TextBox("Hello MIDlet", "Hello,World!", 15, 0);
			tb.addCommand(exitCommand);
			tb.addCommand(listCommand);
			tb.setCommandListener(this);	
			
			String[] stringArray = {
	                "List 1", 
	                "List 2", 
	                "List 3",
					"List 4"
	            };
	       mainList = new List("Choose type", Choice.IMPLICIT, stringArray, null);
	       mainList.addCommand(exitCommand);
	       mainList.setCommandListener(this);
	       
	       display = Display.getDisplay(this);
	       
		}


		protected void startApp() throws MIDletStateChangeException {
			display.setCurrent(tb);			
		}

		protected void pauseApp() {		

		}

		protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

		}


		public void commandAction(Command c, Displayable d) {
			if (c == exitCommand && d == tb) {//结束程序
				try {
					destroyApp(false);
				} catch (MIDletStateChangeException exception) {
					System.out.println("MIDletStateChangeException");
				}
				notifyDestroyed();
			}
			
			if (c == exitCommand && d == mainList) {//返回TextBox屏幕
				display.setCurrent(tb);
			}
			
			if (c == listCommand && d == tb) {//转移到List屏幕				
				display.setCurrent(mainList);
			}
		}

	}

⌨️ 快捷键说明

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