j2me +以递减形式打印数字

时间:2011-07-06 11:50:20

标签: java java-me

我在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();
  }
  }
    }

我的输出位于: - enter image description here

但我想以这种方式: -

而不是串联打印数字..想要打印唯一的单个递减数字。

在屏幕上只有6个 那么屏幕上只有5个

1 个答案:

答案 0 :(得分:1)

StringItem添加到表单中并在任务中设置no并使用它,而不是每次都附加字符串。

参见