Skip to main content

"Please Wait" dialog problem

4 replies [Last post]
bjbcats
Offline
Joined: 2008-08-05
Points: 0

Hi,

I'm trying to use code similar to the makeover demo, roughly this:

Dialog waitDialog = new Dialog();
waitDialog.addComponent(new InfiniteProgressIndicator(....));
....
Command close = new Command("Close");
Dialog resultDialog = new Dialog();
// add some components to resultDialog
resultDialog.addCommand(close);
....

waitDialog.show(.....);
new Thread () {
public void run () {
// do long running stuff
// update resultDialog fields with info
waitDialog.dispose();
resultDialog.show();
}
}.start();

This works OK in that the waitDialog is displayed and animated, then it is disposed and the resultDialog is displayed. The problem is the "close" command doesn't work - there is no way to dispose the resultDialog. I'm wondering if it's to do with this dialog being started from it's own thread ?

The code seems to follow the same pattern as the showMap function in the makeover demo.

Thanks,

Bryan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bjbcats
Offline
Joined: 2008-08-05
Points: 0

Further to this, the problem doesn't seem to be with the way I am using the wait dialog and the result dialog, but is some weird interaction with HttpConnection which I cannot figure out. The complete code snippet is:

new Thread() {
public void run() {
try {
// parts is a list component in the resultDialog
DefaultListModel model = (DefaultListModel) parts.getModel();
model.removeAll();

// get web connection. part is textfield on main form
HttpConnection hc = (HttpConnection) Connector.open(URL + part.getText());

// Turn it into a reader
InputStreamReader isr = new InputStreamReader(hc.openInputStream());

char[] buffer = new char[1024];
StringBuffer line = new StringBuffer();

int n;
while ((n = isr.read(buffer)) > 0) {
line.append(buffer, 0, n);
}

isr.close();
hc.close();
System.err.println(line.toString());

// fill out resultDialog
parseInfo(line.toString(), model);

} catch (Exception ex) {
Dialog.show("Error", ex.getMessage(), null, "Close");
} finally {
waitDialog.dispose();
resultDialog.show();
}
}
}.start();

If I comment out all the web access stuff, it all works fine. With the web access code enabled, _sometimes_ in the emulator the resultDialog can be closed, sometimes not. Running on an actual device (Motorola) it always freezes. I can't for the life of me figure out what the problem is.

Bryan

Mixa

Then indeed it looks like the problem you mentioned before - calling
show() method outside EDT. Try to move it to separate place and call
via Display.callSerially().

I would also make sure that the app doesn't hang somewhere in
Connector.open() or read IO methods.

Mike

On Mon, Mar 1, 2010 at 1:59 PM, wrote:
> Further to this, the problem doesn't seem to be with the way I am using the wait dialog and the result dialog, but is some weird interaction with HttpConnection which I cannot figure out. The complete code snippet is:
>
> new Thread() {
>   public void run() {
>      try {
>          // parts is a list component in the resultDialog
>          DefaultListModel model = (DefaultListModel) parts.getModel();
>          model.removeAll();
>
>          // get web connection. part is textfield on main form
>         HttpConnection hc = (HttpConnection) Connector.open(URL + part.getText());
>
>         // Turn it into a reader
>         InputStreamReader isr = new InputStreamReader(hc.openInputStream());
>
>         char[] buffer = new char[1024];
>         StringBuffer line = new StringBuffer();
>
>         int n;
>         while ((n = isr.read(buffer)) > 0) {
>               line.append(buffer, 0, n);
>         }
>
>         isr.close();
>         hc.close();
>         System.err.println(line.toString());
>
>         // fill out resultDialog
>         parseInfo(line.toString(), model);
>
>     } catch (Exception ex) {
>         Dialog.show("Error", ex.getMessage(), null, "Close");
>     } finally {
>         waitDialog.dispose();
>         resultDialog.show();
>     }
>   }
> }.start();
>
> If I comment out all the web access stuff, it all works fine. With the web access code enabled, _sometimes_ in the emulator the resultDialog can be closed, sometimes not. Running on an actual device (Motorola) it always freezes. I can't for the life of me figure out what the problem is.
>
> Bryan
> [Message sent by forum member 'bjbcats' (bjbcats@tpg.com.au)]
>
> http://forums.java.net/jive/thread.jspa?messageID=389336
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

bjbcats
Offline
Joined: 2008-08-05
Points: 0

Mike,

Following your suggestion, I ended up using

Display.getInstance().invokeAndBlock(new blah());

which works fine. Thanks.

Bryan

Mixa

Hi,

My understanding of LWUIT concepts is following:

Switching between forms (and Dialogs, as they are subclass of Form) is
done via show() method (except for special case of modal dialogs shown
by static 'show' methods).

Dispose() is applicable only for modal dialogs, it returns to a screen
under the dialog. In regular case of non-modal screens (most of
screens in an app) you switch them via show() method - just each
replaces other.

So your 'close' command in result dialog should show some other
screen. Does it work?

Mike

On Mon, Mar 1, 2010 at 8:19 AM, wrote:
> Hi,
>
> I'm trying to use code similar to the makeover demo, roughly this:
>
> Dialog waitDialog = new Dialog();
> waitDialog.addComponent(new InfiniteProgressIndicator(....));
> ....
> Command close = new Command("Close");
> Dialog resultDialog = new Dialog();
> // add some components to resultDialog
> resultDialog.addCommand(close);
> ....
>
> waitDialog.show(.....);
> new Thread () {
>    public void run () {
>         // do long running stuff
>         // update resultDialog fields with info
>         waitDialog.dispose();
>         resultDialog.show();
>    }
> }.start();
>
> This works OK in that the waitDialog is displayed and animated, then it is disposed and the resultDialog is displayed. The problem is the "close" command doesn't work - there is no way to dispose the resultDialog. I'm wondering if it's to do with this dialog being started from it's own thread ?
>
> The code seems to follow the same pattern as the showMap function in the makeover demo.
>
> Thanks,
>
> Bryan
> [Message sent by forum member 'bjbcats' (bjbcats@tpg.com.au)]
>
> http://forums.java.net/jive/thread.jspa?messageID=389303
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net