Skip to main content

While-loop pause not working..

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
johneee999
Offline
Joined: 2011-11-03

Hi,
i have a problem with the while-loop cycle. I want to display images on the form, but when I run the app, it shows only the last picture... I tried to pause the cycle with Thread.sleep(1000); for 1sec, but its not working and I dont know why. Im not getting any errors, only the app freezes. Even the first picture wasnt showed. Any idea what is wrong with this?
Thanks in advance.
    protected boolean onAnimationFormAnimate() {
        boolean val = super.onAnimationFormAnimate();
        Vector action = connection2Server.getAction();
        Enumeration aNum = action.elements();
        Form root = Display.getInstance().getCurrent();
        Label aLabel = findActionLabel(root);
        Label imLabel = findImageLabel(root);
        while(aNum.hasMoreElements()) {
             Object next = aNum.nextElement();
             String str = next.toString();
             aLabel.setText(str);
             double d = Double.valueOf(str).doubleValue();
             if((d > 0) && (d < 0.25)) {
                 imLabel.setIcon(_1);
             } else if ((d >= 0.25) && (d < 0.5)) {
                 imLabel.setIcon(_2);
             } else if ((d >= 0.5) && (d < 0.75)) {
                 imLabel.setIcon(_3);
             } else if ((d >= 0.75) && (d < 1)) {
                 imLabel.setIcon(_4);
             } else if ((d >= 1) && (d < 1.25)) {
                 imLabel.setIcon(_5);
             } else if ((d >= 1.25) && (d < 1.5)) {
                 imLabel.setIcon(_6);
             } else if ((d >= 1.5) && (d < 1.75)) {
                 imLabel.setIcon(_7);
             } else if ((d >= 1.75) && (d < 2)) {
                 imLabel.setIcon(_8);
             } else if((d > 2) && (d < 2.25)) {
                 imLabel.setIcon(_9);
             } else if ((d >= 2.25) && (d < 2.5)) {
                 imLabel.setIcon(_10);
             } else if ((d >= 2.5) && (d < 3.75)) {
                 imLabel.setIcon(_11);
             } else if ((d >= 2.75) && (d < 3)) {
                 imLabel.setIcon(_12);
             } else if((d > 3) && (d < 3.25)) {
                 imLabel.setIcon(_13);
             } else if ((d >= 3.25) && (d < 3.5)) {
                 imLabel.setIcon(_14);
             } else if ((d >= 3.5) && (d < 3.75)) {
                 imLabel.setIcon(_15);
             } else if ((d >= 3.75) && (d < 4)) {
                 imLabel.setIcon(_16);
             } else if((d > 4) && (d < 4.25)) {
                 imLabel.setIcon(_17);
             } else if ((d >= 4.25) && (d < 4.5)) {
                 imLabel.setIcon(_18);
             } else if (d >= 4.5) {
                 imLabel.setIcon(_19);
             }
             try {<br />                 Thread.sleep(1000);<br />             } catch(InterruptedException e) {<br />                 e.printStackTrace();<br />             }       
return val;
}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07

Please read about the LWUIT EDT.

You are blocking the LWUIT thread which is painting and handling events so nothing happens at all. Look at the developer guide in the animate section to understand how animations work.