欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

J2ME 常用组件测试

程序员文章站 2022-03-02 19:36:43
...
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;
import javax.microedition.midlet.MIDletStateChangeException;
/*
 		注:一个TextBox 必须附加一个命令,否则,用户将不能激发任何行为
 		六种限制类型:TextField.ANY  TextField.EMAILADDR  TextField.NUMERIC  TextField.DECIMAL
 					 TextField.PHONENUMBER  TextField.URL
 			
 *
 *
 */

//组件测试  用户输入数据
public class TextBox_test extends MIDlet implements CommandListener {
	private Display display;
	public TextBox_test(){
		super();
		//初始化对象
		display = Display.getDisplay(this);
	}
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub
		
	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		//textBox 组件测试
		//四个参数代表的意思:title,默认值,最大程度,类型
		TextBox tb = new TextBox("记事本","",200,TextField.ANY);
		tb.addCommand(new Command("确定",Command.OK,1));
		tb.setCommandListener(this);
		display.setCurrent(tb);
	}

	public void commandAction(Command c, Displayable d) {
		// TODO Auto-generated method stub
		if(c.getLabel().equals("确定")){
			TextBox tb = (TextBox)d;
			int maxValue = tb.getMaxSize();
			String content = tb.getString();
			System.out.println("内容:"+content);
		}
	}

}
相关标签: J2ME 组件