J2ME road——J2ME实现TextField登录界面

来源:互联网 发布:淘宝网首页茵曼 编辑:程序博客网 时间:2024/05/24 13:28

package src;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class TextBoxTest extends MIDlet implements CommandListener{
 
 private TextBox textbox;
 private Alert   alert;
 private Command quit;
 private Command go;
 
 public TextBoxTest()
 {
  textbox = new TextBox("Enter Thy Name","Sir",20,TextField.ANY);
  go   = new Command("Go", Command.SCREEN, 1);
  quit = new Command("Quit", Command.EXIT, 2);
  textbox.addCommand(go);
  textbox.addCommand(quit);
  textbox.setCommandListener(this);
 }
 
 protected void destroyApp(boolean b) throws MIDletStateChangeException {
  // TODO destroyApp
  
 }

 protected void pauseApp() {
  // TODO pauseApp
  
 }

 protected void startApp() throws MIDletStateChangeException {
  // TODO pauseApp
  Display.getDisplay(this).setCurrent(textbox);
 }

 public void commandAction(Command c, Displayable d) {
  // TODO commandAction
  try
  {
   if(c==quit)
   {
    destroyApp(true);
    notifyDestroyed();
   }
   if(c==go)
   {
    alert = new Alert("", "Greetings "+textbox.getString(),null,AlertType.CONFIRMATION);
    Display.getDisplay(this).setCurrent(alert);
   }
  }
  catch (MIDletStateChangeException e)
  {
   System.out.println(e + "caught.s");
  }
 }

}

原创粉丝点击