【J2ME】TextBox

来源:互联网 发布:linux sleep 实现 编辑:程序博客网 时间:2024/05/17 04:29

package cn.edu.zucc.exp1;

 

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


public class MyMidlet extends MIDlet implements CommandListener {

 

    private Display display;
    private Form form = null;
    private Command exit;
    private Command ok;
    private Command clear;
    private TextBox textbox;


    public MyMidlet() {
        display = Display. getDisplay_r(this);
    }

 

    public void startApp() {
        exit = new Command("exit", Command.EXIT, 1);
        ok = new Command("ok", Command.SCREEN, 2);
        clear = new Command("clear", Command.SCREEN, 2);

 

        textbox = new TextBox("TextBox", "", 30, TextField.ANY);
        textbox.addCommand(ok);
        textbox.addCommand(clear);
        textbox.setCommandListener(this);

 

        form = new Form("MyMidlet");
        form.addCommand(exit);
        form.setCommandListener(this);

 

        display.setCurrent(textbox);
    }

 

    public void pauseApp() {
    }

 

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }

 

    public void commandAction(Command c, Displayable d) {
        if (c == ok) {
            String str = textbox. getString_r();
            form.append(str);
            display.setCurrent(form);
        } else if (c == clear) {
            textbox.setString(null);
        } else {
            destroyApp(true);
        }
    }


}

原创粉丝点击