Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [J2ME] Repeatedly displaying values in a form does not work

Reply
Thread Tools

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

 
 
acme82
Guest
Posts: n/a
 
      03-13-2008
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.MIDletStateChangeExcepti on;


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aspnet_wp.exe Repeatedly stopping and being recycled unexpectedly Jarrod Hermer ASP .Net 2 07-13-2007 01:39 PM
OO is not that great[2]: repeatedly passing the same object Shawn Java 5 09-25-2006 07:54 AM
OO is not that great[2]: repeatedly passing the same member reference Shawn Java 1 09-22-2006 06:36 PM
Repeatedly Disconnect and Connect =?Utf-8?B?cGF0aWxw?= Wireless Networking 0 02-18-2005 03:17 PM
VS.NET Bug - event handlers clobbered repeatedly SteveLB ASP .Net 0 08-08-2003 04:02 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57