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

Discussion in 'Java' started by acme82, Mar 13, 2008.

  1. acme82

    acme82 Guest

    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
     
    acme82, Mar 13, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SteveLB
    Replies:
    0
    Views:
    338
    SteveLB
    Aug 8, 2003
  2. Jarrod Hermer
    Replies:
    2
    Views:
    2,237
    kahlawat
    Jul 13, 2007
  3. Dan
    Replies:
    4
    Views:
    488
    Mr Newbie
    Dec 30, 2005
  4. Shawn
    Replies:
    1
    Views:
    312
    opalinski from opalpaweb
    Sep 22, 2006
  5. Shawn
    Replies:
    5
    Views:
    347
    Hendrik Maryns
    Sep 25, 2006
Loading...

Share This Page