Java ME Hello World

附件为J2ME所有源码











import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class FirstProMIDlet extends MIDlet implements CommandListener {

	private Command exitCommand;
	
	private TextBox tbox;
	
	public FirstProMIDlet(){
		
		exitCommand=new Command("Exit",Command.EXIT,1);
		tbox=new TextBox("Hello world Midlet","Hello World !",25,0);
		tbox.addCommand(exitCommand);
		tbox.setCommandListener(this);
	}
	
	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		Display.getDisplay(this).setCurrent(tbox);
	}
	
	public void commandAction(Command cmd, Displayable disp) {
		// TODO Auto-generated method stub
		if(cmd==exitCommand){
			try {
				destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
			notifyDestroyed();
		}
	}
	
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}
}




猜你喜欢

转载自xiongjiajia.iteye.com/blog/1763088