j2me+print the number in decremental form in form
i m working in j2me.Please help me. I had used the below code:-
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();
}
}
}
And my output is in :-
But i want it in this way:-
instead of printing number in series.. in want the only single decremented number to be printed.
Like only 6 in screen
then only 5 in screenTake a StringItem
add it to form and set the no to it in task and play with it instead of appending the String each time.
See
- Example of StringItem
精彩评论