以文本方式查看主题

-  课外天地 李树青  (http://njcie.com/bbs/index.asp)
--  JavaME移动开发课件  (http://njcie.com/bbs/list.asp?boardid=18)
----  程序代码——TextBox  (http://njcie.com/bbs/dispbbs.asp?boardid=18&id=534)

--  作者:admin
--  发布时间:2008/9/22 23:12:16
--  程序代码——TextBox

import javax.microedition.lcdui.Alert;
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.lcdui.TextField;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet implements CommandListener {
        Display display;

        TextBox textBox;

        Command cmd1 = new Command("显示", Command.ITEM, 1);

        public void startApp() {
                display = Display.getDisplay(this);
                textBox = new TextBox("编辑", "初始值", 50, TextField.ANY);
                textBox.addCommand(cmd1);
                textBox.setCommandListener(this);
                display.setCurrent(textBox);
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }

        public void commandAction(Command c, Displayable s) {
                Alert alert = new Alert("显示");
                alert.setString(textBox.getString());
                alert.setTimeout(2000);
                display.setCurrent(alert);
        }
}

[此贴子已经被作者于2010-12-12 18:27:49编辑过]