0
我在j2me中工作。请帮助我。 我用下面的代码: -j2me +在表格中以递减形式打印数字
protected void startApp() {
display = Display.getDisplay(this);
form = new Form("Item Layout");
TxtData=new TextField("Number","" , 4, TextField.NUMERIC);
GO = new Command("Go", Command.OK, 1);
Exit = new Command("Exit", Command.EXIT, 2);
form.append(TxtData);
form.addCommand(GO);
form.addCommand(Exit);
form.setCommandListener(this);
display.setCurrent(form);
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command cmnd, Displayable dsplbl) {
String label = cmnd.getLabel();
if(label.equals("Go")){
number=Integer.parseInt(TxtData.getString());
timer = new Timer();
task = new TestTimerTask();
timer.schedule(task,500,500);
} else if(label.equals("Exit")){
destroyApp(true);
}
}
private class TestTimerTask extends TimerTask{
public final void run(){
number--;
form.append(""+ number+"\n");
if(number==0){
timer.cancel();
}
}
}
而且我的输出是: -
但我想它是这样的: -
而不是一系列的打印编号。在想要打印唯一的递减数字。
就像在屏幕只有6
则只有5屏幕
感谢您的解决方案可以正常工作 –
你总是受欢迎的。 –