Herbert Meier
2006-09-15 16:00:02 UTC
Hello,
I've the following problem: I want to start a computation in a seperate
thread, while this computation thread is runing the application should
show a dialog to the user with a button to abort the computation. Here
is a code sample:
-------------------------------------------------------------------
// ComputationThread is ab extension of java.lang.Thread which executes
// some long lasting computation in its run() method
ComputationThread thread = new ComputationThread();
// AbortDialog is a modal JDialog which shows a JButton("Abort")
// in actionPerformed() of the ActionListener at this Button
// the computation thread will be stopped: thread.interupt
AbortDialog abortDialog = new AbortDialog(this, thread);
// run computation
thread.start();
// show abortDialog
abortDialog.setVisible(true);
try {
// wait for computation thread to has finished
thread.join();
// dispose the abort dialog
abortDialog.dispose();
// ... do things with the computation results ...
} catch (InterruptedException e) { ... }
-------------------------------------------------------------------
The abort dialog should be modal, thus no other user input in the GUI
should be possile besides pressing the abort-button. But a modal dialog
seems to be waiting till it is closed until execution will proceed,
what means that thread.join won't be reached before closing the abot
dialog. But what i want is, that the abort dialog will be cloes after
thread.join automatically.
Many thanks if anybode could post a solution for this problem.
-herbert
I've the following problem: I want to start a computation in a seperate
thread, while this computation thread is runing the application should
show a dialog to the user with a button to abort the computation. Here
is a code sample:
-------------------------------------------------------------------
// ComputationThread is ab extension of java.lang.Thread which executes
// some long lasting computation in its run() method
ComputationThread thread = new ComputationThread();
// AbortDialog is a modal JDialog which shows a JButton("Abort")
// in actionPerformed() of the ActionListener at this Button
// the computation thread will be stopped: thread.interupt
AbortDialog abortDialog = new AbortDialog(this, thread);
// run computation
thread.start();
// show abortDialog
abortDialog.setVisible(true);
try {
// wait for computation thread to has finished
thread.join();
// dispose the abort dialog
abortDialog.dispose();
// ... do things with the computation results ...
} catch (InterruptedException e) { ... }
-------------------------------------------------------------------
The abort dialog should be modal, thus no other user input in the GUI
should be possile besides pressing the abort-button. But a modal dialog
seems to be waiting till it is closed until execution will proceed,
what means that thread.join won't be reached before closing the abot
dialog. But what i want is, that the abort dialog will be cloes after
thread.join automatically.
Many thanks if anybode could post a solution for this problem.
-herbert