次のコードをご覧ください。
ここでは、「OK」ボタンが応答していません。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TexyFieldExample extends MIDlet implements CommandListener
{
private Form form;
private Display display;
private TextField name, company;
private Command ok;
public TexyFieldExample()
{
name = new TextField("Name","",30,TextField.ANY);
company = new TextField("Company","",30,TextField.ANY);
ok = new Command("OK",Command.OK,2);
}
public void startApp()
{
form = new Form("Text Field Example");
display = Display.getDisplay(this);
form.append(name);
form.append(company);
form.addCommand(ok);
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean destroy)
{
notifyDestroyed();
}
public void commandAction(Command c, Displayable d)
{
String label = c.getLabel();
if(label.equals("ok"))
{
showInput();
}
}
private void showInput()
{
form = new Form("Input Data");
display = Display.getDisplay(this);
form.append(name.getString());
form.append(company.getString());
display.setCurrent(form);
}
}