[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [ajug-members]: Wait()
You need to catch InterruptedException to use it.
Do not call it on the event dispatch thread.
Download SwingWorker from sun (google), wrap your long-running process in
construct() method,
and manipulate the gui in finished() or by using
SwingUtilities.invokeLater(Runnable) or
SwingUtilities.invokeAndWait(Runnable).
invokeAndWait() requires you to catch/throw InvocationTargetException:
i.e.
SwingWorker worker = new SwingWorker() {
public Object construct() {
//your long running process, i.e.
try {
Thread.yield(6000);
} catch (InterruptedException ie) {
//put a joption pop-up on the event queue.
try {
SwingUtilities.invokeAndWait( new Runnable() {
public void run() {
textField.setText("something happened");
JOptionPane.showMessageDialog(null, "What happened?");
}
});
} catch (InterruptedException ie2) {
ie2.printStackTrace();
} catch (InvocationTargetException ite) {
ite.printStackTrace();
}
}
}
//finished is 'on' the event dispatch thread, so it's ok.
public void finished() {
textField.setText("Finished");
}
};
worker.start();
Or something like that.
>Do you have to setup any threads to use it, or can it be used say to show a
>splash screen for x seconds and then continue processing? Do you have to
>declare any includes?
>
>
>Thanks,
>
>
>Cody Wehunt
>cody@wehunt.net
>770-402-9189 Cell
>770-226-5938 Work
>My <http://wehuntnet.instaccount.net/images/two_cent.gif> as always.
>
>
>
> _____
>
>From: Jim Worthington [mailto:jim.worthington@worthsoft.com]
>Sent: Monday, April 26, 2004 4:41 PM
>To: ajug-members@ajug.org
>Subject: RE: [ajug-members]: Wait()
>
>
>Thread.sleep(30000L) is the equivalent. The argument is a long and the
>units
>are milliseconds.
>
>- Jim Worthington
>
>-----Original Message-----
>From: Cody Wehunt [mailto:cody@wehunt.net]
>Sent: Monday, April 26, 2004 4:24 PM
>To: ajug-members@ajug.org
>Subject: [ajug-members]: Wait()
>
>
>Is there a built in wait function in JAVA?
>
>i.e.
>
>wait(30); //hold processing for 30 seconds
>
>
>Thanks,
>
>
>Cody Wehunt
>cody@wehunt.net
>770-402-9189 Cell
>770-226-5938 Work
>My <http://wehuntnet.instaccount.net/images/two_cent.gif> as always.
>
>
>
_________________________________________________________________
Watch LIVE baseball games on your computer with MLB.TV, included with MSN
Premium!
http://join.msn.com/?page=features/mlb&pgmarket=en-us/go/onm00200439ave/direct/01/