import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class TextBoxDemo extends MIDlet implements CommandListener { private Display display=Display.getDisplay(this); private TextBox textBox; private Command cmdOK=new Command("写好了",Command.SCREEN,1); private Command cmdExit=new Command("不写了",Command.SCREEN,2); private Alert alert; public TextBoxDemo() { // TODO Auto-generated constructor stub textBox=new TextBox("呆,输入电话号码","",11,TextField.PHONENUMBER); textBox.addCommand(cmdOK); textBox.addCommand(cmdExit); textBox.setCommandListener(this); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { // TODO Auto-generated method stub } protected void pauseApp() { // TODO Auto-generated method stub } protected void startApp() throws MIDletStateChangeException { // TODO Auto-generated method stub display.setCurrent(textBox); } public void commandAction(Command arg0, Displayable arg1) { // TODO Auto-generated method stub if(arg0==cmdOK) { alert=new Alert("发送","",null,AlertType.INFO); alert.setTimeout(3000); alert.setString("正在发送……"); display.setCurrent(alert, display.getCurrent());//将该对话框设置为当前的屏幕 } else if(arg0==cmdExit) { try { destroyApp(false); } catch (MIDletStateChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); } notifyDestroyed(); } } }