I have multiple classes extending the SwingWorker. What I wish to accomplish is to execute each class one after another (without executing the next class in the previous class' done method). For example, lets say I have:
ClassSwingW1 csw1 = new ClassSwingW1();
csw1.execute;
ClassSwingW2 csw2 = new ClassSwingW2();
csw2.execute;
ClassSwingW3 csw3 = new ClassSwingW3();
csw3.execute;
and etc.
public class ClassSwingW1 extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
//do something
return null;
}
}
public class ClassSwingW2 extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
//do something
return null;
}
}
public class ClassSwingW3 extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
//do something
return null;
}
}
I want the csw2 to execute after csw1 is done, and csw3 to execute after csw2 is done. I do not want them executing at the same time. How would I accomplish this? Thank you
You could use the get()
method instead of execute()
- it will block until the SwingWorker finishes its job. Just make sure that you don't call it from the EDT.
Javadoc extract:
Waits if necessary for the computation to complete, and then retrieves its result. Note: calling get on the Event Dispatch Thread blocks all events, including repaints, from being processed until this SwingWorker is complete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With