import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class testbox1 extends MIDlet implements CommandListener{
private TextBox tb=new TextBox("请你输入短信","",255,TextField.ANY); //无限制输入
private Display dis;
private Command comgetpos=new Command("获得光标位置",Command.SCREEN,1);
private Command comset=new Command("获得光标位置",Command.BACK,1);
public testbox1() {
// TODO Auto-generated constructor stub
}
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
dis=Display.getDisplay(this);
dis.setCurrent(tb);
tb.addCommand(comgetpos);
tb.addCommand(comset);
tb.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
// TODO Auto-generated method stub
if(c.equals(comgetpos))
{tb.setTitle("光标位置"+tb.getCaretPosition()); //获取光标位置
System.out.println("输入的文本"+tb.getString());
tb.insert(tb.getString(), tb.getCaretPosition());} //插入字符
if(c.equals(comset))
{char[] ch={'叼'};
tb.setChars(ch, 0, 1);} //更改字符
}
}