[J2ME] Repeatedly displaying values in a form does not work

A

acme82

Hello,

the problem I am currently facing is the following:

J2ME seems to "optimize" my code in such a way that repeated outputs
to a GUI-Element such as a StringItem are not performed and only the
last of the
values is actually written to the output.
If you take for example a loop as shown below, J2ME only writes the
last value to the output, there is no continous output as expected.
Since I am
wrtiting a countdown-application, this is exactly what I do need. I
would like to get an output e.g. every second. Is there a way to
tackle this issue?
I have also tried to use a canvas and its repaint() method but the
behavior is exactly the same.

{code}
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class OutputTest extends MIDlet implements CommandListener {

private Command exitCommand;
private Form form;
private Display display;
private StringItem output;

public OutputTest() {
display = Display.getDisplay(this);
form = new Form("Test Midlet");
exitCommand = new Command("Exit", Command.EXIT, 2);
form.addCommand(exitCommand);
form.setCommandListener(this);
output = new StringItem("","");
form.append(output);

// Test loop, shows the value 0 after some computation,
// but not as expected the decrementing value before
for (int i=0; i<1000000;i++){
output.setText("Output: " + i);
}

// the loop above is replaced by a countdown()-method which
// does a output.setText(remainingTime) every second.
// this.countdown()

}

protected void startApp() throws MIDletStateChangeException {
display.setCurrent(form);
}

protected void pauseApp() {
}

protected void destroyApp(boolean arg0) throws
MIDletStateChangeException {
}

public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
notifyDestroyed();
}
}

}

{code}


Thanks in advance,

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top