pr******************@indiatimes.com (priyanka) wrote in message news:<32**************************@posting.google. com>...
[snipped...]
hi all
My que is related to J2ME. I am trying to show the loading screen
on a handset by filling of Gauge bars one by one.but ut doesnt worked
so. what it does that it just wait for some secs (coz of
Thresd.sleep()) and then fill all the bars simultaneously..here is the
code of program
[snipped...] public void commandAction(Command c,Displayable d) {
try {
for (int j=0;j<=7;j++) {
gauge.setValue(j);
Thread.sleep(1000);
}
}
catch(InterruptedException ie){
}
}
}
I am using J2ME Wireless Toolkit 1.0.4 with KToolbar.All solutions
will be welomed.
pink
From what little J2ME I recall, commandAction is some kind of event
handler, correct? To put it in simplified terms, J2ME's UI thread
has called your event handler - your event handler then hogs the
thread for 7 or so seconds, updating the gauge, but as you are running
*your* code on the UI's thread, the UI never has an opportunity to
update until you release control of the thread when your event handler
exits. (A race condition, in threading terms!)
As a general rule of thumb: when programming event handlers in Java,
you are running on someone else's thread - so get your work done and
get the hell out of there ASAP! ;-)
(The similar deadlock effect can be had by opening a 'Chooser' type
dialog from inside an event handler in Swing, and waiting for its
response.)
You'll have to find some other way of periodically calling the
code which changes the gauge status, one which does not hog the
UI's event firing thread. This could be as simple as firing off
a separate thread for your loop - or finding an in-built J2ME
mechanism to re-call actionCommand periodically.
-FISH- ><>