import javax.microedition.lcdui.*;
//テキストボックスを使う(フォーム)
class TextBoxForm extends Form
implements CommandListener {
StringItem stringItem;//文字列アイテム
TextBox textBox; //テキストボックス
//コンストラクタ
public TextBoxForm(){
super("TextBoxEx");
//文字列アイテム
stringItem=new StringItem("文字列","");
append(stringItem);
//テキストボックス
textBox=new TextBox("","",200,TextField.ANY);
textBox.addCommand(new Command("OK",Command.SCREEN,1));
textBox.setCommandListener(this);
//ソフトキー
addCommand(new Command("入力",Command.SCREEN,0));
setCommandListener(this);
}
//ソフトキーイベント
public void commandAction(Command c,Displayable s) {
//テキストボックスを開く
if (c.getPriority()==0) {
textBox.setString(stringItem.getText());
Display.getDisplay(TextBoxEx.current).setCurrent(textBox);
}
//テキストボックスを閉じる
if (c.getPriority()==1) {
stringItem.setText(textBox.getString());
Display.getDisplay(TextBoxEx.current).setCurrent(this);
}
}
}
|