midlettwo.java

来自「java手机程序开发随书光盘源代码」· Java 代码 · 共 65 行

JAVA
65
字号
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class MIDletTwo extends MIDlet implements Runnable, CommandListener{	Thread thread;	List list;	int number = 0;	Display display;	Command switchCmd;	Command exitCmd;	boolean first = true;		public MIDletTwo(){		list = new List("MIDletTwo", List.IMPLICIT);		list.append("MIDlet Two:"+number, null);		thread = new Thread(this);		switchCmd = new Command("Switch",Command.SCREEN,1);		exitCmd = new Command("Exit",Command.EXIT,1);		display = Display.getDisplay(this);		list.addCommand(switchCmd);		list.addCommand(exitCmd);		list.setCommandListener(this);	}	public void startApp(){				System.out.println("OK");				if(first){			thread.start();			first = false;		}		display.setCurrent(list);	}		public void run(){		while(true){			try{				Thread.sleep(2000);				number++;				list.set(0,"MIDlet Two:"+number, null);			}catch(Exception e){}		}	}	public void pauseApp(){	}	public void destroyApp(boolean unconditional){		thread = null;	} 	public void commandAction(Command c, Displayable d){		if(c == switchCmd){			pauseApp();			notifyPaused();				resumeRequest();		}else if(c == exitCmd){			destroyApp(false);			notifyDestroyed();		}	}}

⌨️ 快捷键说明

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