helloworld.java

来自「J2ME手机游戏入门程序」· Java 代码 · 共 59 行

JAVA
59
字号
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class helloworld extends MIDlet  implements CommandListener{
	private Command  exitcommand;
    private TextBox tb;
    
	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
    public helloworld(){
    	exitcommand=new Command("exit",Command.EXIT,1);
    	tb=new TextBox("hello midlet","hello,word",15,0);
    	tb.addCommand(exitcommand);
    	tb.setCommandListener(this);
    	
    	}
	protected void startApp() throws MIDletStateChangeException {
		Display.getDisplay(this).setCurrent(tb);
		System.out.println("startApp");
		
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {
		// TODO Auto-generated method stub
		System.out.println("pauseApp");
		
	}

	/* (non-Javadoc)
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		System.out.println("destoryApp");
	}

	/* (non-Javadoc)
	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable)
	 */
	public void commandAction(Command c, Displayable d) {
	
		if(c == exitcommand){
			try{
				destroyApp(false);
				
				}catch(MIDletStateChangeException exception){
					System.out.println("MIDletStateChangeException");} 
				
          notifyDestroyed();
          
			}

}
}

⌨️ 快捷键说明

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