textfielddemo.java

来自「微型JAVA人编写的J2ME教材! 中带的原代码!简单易懂」· Java 代码 · 共 47 行

JAVA
47
字号
//TextFieldDemo.java
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class TextFieldDemo 
	extends MIDlet implements CommandListener {

    private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    
    protected void startApp() {
        Form f = new Form("Text Field");
        f.append("This demo contains text fields each one " +
                "with a different constraint");

        f.append(new TextField
			("Any Character", "English", 15, TextField.ANY));
        f.append(new TextField
			("E-Mail", "woo@yahoo.com", 15, TextField.EMAILADDR));
        f.append(new TextField
			("Number", "9876", 15, TextField.NUMERIC));
        f.append(new TextField
			("Decimal", "12.34", 15, TextField.DECIMAL));
        f.append(new TextField
			("Phone", "086010762768899", 20, TextField.PHONENUMBER));
        f.append(new TextField
			("Password", "pwdandpwd", 15, TextField.PASSWORD));
        f.append(new TextField
			("URL", "http://www.pku.edu.cn", 25, TextField.URL));
        
        f.addCommand(exitCommand);
        f.setCommandListener(this);
        Display.getDisplay(this).setCurrent(f);
    }
    
    public void commandAction(Command c, Displayable s) {
	if (c == exitCommand) {
	    destroyApp(false);
	    notifyDestroyed();
	}	
    }
    
    protected void destroyApp(boolean unconditional) {
    }
    
    protected void pauseApp() {
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?