Board index » jbuilder » Java equivalent of Application.ProcessMessages() ?

Java equivalent of Application.ProcessMessages() ?


2004-04-02 10:48:52 PM
jbuilder12
Hello All,
I am writing a stand alone Java application (using JBuilder X Developer) in
which the user enters some parameters, hits an "OK" button to begin the
computations, and then the app takes a while to do its work. I have created
a small progress window with a JProgressBar that I show while the app is
working, to give the user some visual feedback.
However, I cannot figure out how to, from within the computation loop (e.g.,
a 'for' loop), pass control back to the main app or system in order to
refresh/repaint the frames. The frame looks frozen and doesn't repaint
itself until after the loop is done. I have tried methods like validate,
repaint, and updateUI, but to no avail. Basically I need an equivalent to
the Delphi/CBuilder Application.ProcessMessages() method.
Any help is appreciated.
Regards,
Todd Eischeid
 
 

Re:Java equivalent of Application.ProcessMessages() ?

Todd M. Eischeid wrote:
Quote
Hello All,

I am writing a stand alone Java application (using JBuilder X Developer)
in which the user enters some parameters, hits an "OK" button to begin the
computations, and then the app takes a while to do its work. I have
created a small progress window with a JProgressBar that I show while the
app is working, to give the user some visual feedback.

However, I cannot figure out how to, from within the computation loop
(e.g., a 'for' loop), pass control back to the main app or system in order
to
refresh/repaint the frames. The frame looks frozen and doesn't repaint
itself until after the loop is done. I have tried methods like validate,
repaint, and updateUI, but to no avail. Basically I need an equivalent to
the Delphi/CBuilder Application.ProcessMessages() method.

Any help is appreciated.

Regards,
Todd Eischeid
Several Ways to approach this, so I am unsure of exactly which way you want
to approach it.
(1) You could create a thread for the computational process. Synchronize
that thread so that it keeps operatons in sync.
(2) Use a timer to timeout the operations until the processes finish.
(3) Try using the javax.swing.SwingUtilities to bring screens back into
focus. You could use the SwingUtilities.invokeLater() or
SwingUtilities.invokeAndWait() methods. These would be close to
Application.ProcessMessages.
csunix1.lvc.edu/~ys02/docs/api/javax/swing/SwingUtilities.html
 

Re:Java equivalent of Application.ProcessMessages() ?

Thanks, I was not aware of the SwingUtilities class, which sounds like a
good way to go. I'll give that a whirl.
Todd
"pnichols" < XXXX@XXXXX.COM >wrote in message
Quote
Todd M. Eischeid wrote:

>Hello All,
>
>I am writing a stand alone Java application (using JBuilder X Developer)
>in which the user enters some parameters, hits an "OK" button to begin
the
>computations, and then the app takes a while to do its work. I have
>created a small progress window with a JProgressBar that I show while
the
>app is working, to give the user some visual feedback.
>
>However, I cannot figure out how to, from within the computation loop
>(e.g., a 'for' loop), pass control back to the main app or system in
order
>to
>refresh/repaint the frames. The frame looks frozen and doesn't repaint
>itself until after the loop is done. I have tried methods like
validate,
>repaint, and updateUI, but to no avail. Basically I need an equivalent
to
>the Delphi/CBuilder Application.ProcessMessages() method.
>
>Any help is appreciated.
>
>Regards,
>Todd Eischeid

Several Ways to approach this, so I am unsure of exactly which way you
want
to approach it.

(1) You could create a thread for the computational process. Synchronize
that thread so that it keeps operatons in sync.

(2) Use a timer to timeout the operations until the processes finish.

(3) Try using the javax.swing.SwingUtilities to bring screens back into
focus. You could use the SwingUtilities.invokeLater() or
SwingUtilities.invokeAndWait() methods. These would be close to
Application.ProcessMessages.

csunix1.lvc.edu/~ys02/docs/api/javax/swing/SwingUtilities.html

 

{smallsort}