⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textboxtest.java

📁 《精彩的手机UI例程.zip》是很好的手机编辑软件
💻 JAVA
字号:

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

public class TextBoxTest extends MIDlet implements CommandListener{
    private List    startmenu;
    private TextBox textBox;
    private Command okCommand = new Command("OK", Command.OK, 1);
    private Command backCommand = new Command("Back", Command.BACK, 1);
    /**
     * These are the labels for the supported textboxes.
     */
    private static final String[] textBoxLabels = {
            "Any Character",
            "E-Mail",
            "Number",
            "Phone",
            "Url",
            "Password",
    };
    private static final String[] text = {
            "This is my info:",
            "jzhu@webyu.com",
            "91320",
            "3762659",
            "www.webyu.com",
            "1234",
    };
    /**
     * These are the supported textbox types.
     */
    private static final int[] textBoxTypes = {
            TextField.ANY,
            TextField.EMAILADDR,
            TextField.NUMERIC,
            TextField.PHONENUMBER,
            TextField.URL,
            TextField.PASSWORD
    };
            
    private Display display;
	
    public TextBoxTest() {
    	//create an implicit choice list, and use it as start menu
	startmenu= new List("Select a Text Box Type", List.IMPLICIT,textBoxLabels,
			    null);
	startmenu.setCommandListener(this);
	//retrieve display object 
	display=Display.getDisplay(this);
    }
    
    public void startApp() throws MIDletStateChangeException {
        display.setCurrent(startmenu);
    }

    /**
     * Pause the MIDlet
     */
    public void pauseApp() {
    }

    /**
     * Called by the framework before the application is unloaded
     */
    public void destroyApp(boolean unconditional) {
        startmenu=null;
	textBox=null;
	okCommand = null;
	backCommand = null;
    }

    public void commandAction(Command c, Displayable d) {
        if(d==startmenu && c==List.SELECT_COMMAND) {
            int selected_num=startmenu.getSelectedIndex();
            textBox= new TextBox(null,"",150,textBoxTypes[selected_num]);
	    textBox.addCommand(okCommand);
	    textBox.addCommand(backCommand);
	    textBox.setCommandListener(this);

            try {
                textBox.setString("This is my info:");
                //textBox.setString(text[selected_num]);
            }catch(Exception e) {
                System.out.println("Error: "+e.getMessage());
            }

            textBox.setTitle(textBoxLabels[selected_num]);
	    display.setCurrent(textBox);
	}
	else if(c==okCommand) {
	    //output the text typed
	    System.out.println("text="+textBox.getString());
            int constraint= TextField.CONSTRAINT_MASK&textBox.getConstraints();
            System.out.println("Constaint="+textBoxLabels[constraint]);
            if(textBox.getConstraints()>=TextField.PASSWORD) {
                System.out.println("Modifier=PASSWORD");    
            }
	}
	else if(c==backCommand) {
	    display.setCurrent(startmenu);
	}
    }
}

⌨️ 快捷键说明

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