J2me-TextField类

一、代码

package hello;

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


public class HelloMIDlet extends MIDlet implements CommandListener{

privateboolean midletPaused = false;

//<editor-fold defaultstate="collapsed" desc="Generated Fields ">
privateCommand exitCommand;
privateCommand okCommand;
private Formform;
privateTextField passtext;
//</editor-fold>


publicHelloMIDlet() {
}

//<editor-fold defaultstate="collapsed" desc="Generated Methods ">
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Method: initialize ">

private voidinitialize() {
// write pre-initialize user code here

// write post-initialize user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Method: startMIDlet ">

public voidstartMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Method: resumeMIDlet ">

public voidresumeMIDlet() {
// write pre-action user code here

// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Method: switchDisplayable ">

public voidswitchDisplayable(Alert alert, Displayable nextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Method: commandAction for Displayables">

public voidcommandAction(Command command, Displayable displayable) {
// write pre-action user code here
if (displayable == form) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (command == okCommand) {
// write pre-action user code here
passtext.setConstraints(TextField.ANY);
passtext.setString("设置成功");
form.removeCommand(okCommand);


// write post-action user code here
}
}
// write post-action user code here
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Getter: exitCommand ">

publicCommand getExitCommand() {
if (exitCommand == null) {
// write pre-init user code here
exitCommand = new Command("Exit", Command.EXIT, 0);
// write post-init user code here
}
return exitCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Getter: form ">

public FormgetForm() {
if (form == null) {
// write pre-init user code here
form = new Form("Welcome", new Item[] { getPasstext() });
form.addCommand(getExitCommand());
form.addCommand(getOkCommand());
form.setCommandListener(this);
// write post-init user code here
}
return form;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Getter: okCommand ">

publicCommand getOkCommand() {
if (okCommand == null) {
// write pre-init user code here
okCommand = new Command("\u786E\u5B9A", Command.OK, 0);
// write post-init user code here
}
return okCommand;
}
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Generated Getter: passtext ">

publicTextField getPasstext() {
if (passtext == null) {
// write pre-init user code here
passtext = new TextField("\u8BBE\u7F6E\u5BC6\u7801", null, 32,TextField.ANY | TextField.PASSWORD);
// write post-init user code here
}
return passtext;
}
//</editor-fold>


publicDisplay getDisplay () {
return Display.getDisplay(this);
}


public voidexitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}


public voidstartApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}


public voidpauseApp() {
midletPaused = true;
}


public voiddestroyApp(boolean unconditional) {
}

}

你可能感兴趣的:(textfield)