Skip to main content

About Form.show()

5 replies [Last post]
kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hi all,

I have a CustomForm and in its constructor i call show() before starting a Thread that will grab some images from the net. When the Thread has the images, it makes something like this:

((CustomForm)Display.getInstance().getCurrent()).update();

I know there are better ways to do this, as this could drive to ClassCastException as in my case. Although I call show() before throwing the requester Thread, that doesn't guarantee the Form is already shown when the image arrives to the client.

Is there any easy and elegant way to be sure the Form is shown before starting the thread?? Or it's just better to implement some kind of requester interface to know who started the Thread, and to whom the Thread must call the update() method (to load the received images)??

Thanks and regards

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Hi again Shai,

I tried overriding onShow() and doesn't work for me. onShow() i start the Thread and it grabs the images. At that point, the screen is not yet the Form i'm trying to show, but the previous one.

Could you point me on right direction about how to use isEDT method? I was trying something like this but it's not abandoning the loop...

this.show();
while (!Display.getInstance().isEDT()) {};
startThread();

Thanks

Shai Almog

Hi,
since isEDT() will only return true when you are running on the Event
Dispatch Thread you essentially loop indefinitely since it will
always return false for that thread. You need to call show() either
as a result of a LWUIT event (which will always be delivered on the
EDT) or within the runnable of callSerially.
This will also cause onShow() to work as expected.

> Hi again Shai,
>
> I tried overriding onShow() and doesn't work for me. onShow() i
> start the Thread and it grabs the images. At that point, the screen
> is not yet the Form i'm trying to show, but the previous one.
>
> Could you point me on right direction about how to use isEDT
> method? I was trying something like this but it's not abandoning
> the loop...
>
> this.show();
> while (!Display.getInstance().isEDT()) {};
> startThread();
>
> Thanks
> [Message sent by forum member 'kawaiimomo' (kawaiimomo)]
>
> http://forums.java.net/jive/thread.jspa?messageID=301595
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Thanks again, you are so kind :-)

Shai Almog

Hi,
to make sure form.show() completes just call it from the EDT (use
isEDT) to check that. As long as you don't have a transition there
shouldn't be a problem.

An alternative approach is to override onShow().

> Hi all,
>
> I have a CustomForm and in its constructor i call show() before
> starting a Thread that will grab some images from the net. When the
> Thread has the images, it makes something like this:
>
> ((CustomForm)Display.getInstance().getCurrent()).update();
>
> I know there are better ways to do this, as this could drive to
> ClassCastException as in my case. Although I call show() before
> throwing the requester Thread, that doesn't guarantee the Form is
> already shown when the image arrives to the client.
>
> Is there any easy and elegant way to be sure the Form is shown
> before starting the thread?? Or it's just better to implement some
> kind of requester interface to know who started the Thread, and to
> whom the Thread must call the update() method (to load the received
> images)??
>
> Thanks and regards
> [Message sent by forum member 'kawaiimomo' (kawaiimomo)]
>
> http://forums.java.net/jive/thread.jspa?messageID=301553
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

kawaiimomo
Offline
Joined: 2008-07-10
Points: 0

Thank you Shai

Regards