Click to See Complete Forum and Search --> : ProgressMonitor Dialog.


agniputhran
May 3rd, 2000, 05:03 AM
Hi,

I tried an example with progress monitor as given
in 'Core Java' book. While the 'cancel' button is
handled, the 'X' window closing button is not.

If i 'Cut' the dialog, the background thread goes
on and the status of the ProgressMonitor dialog
is not 'canceled'.

Any ideas how to handle the 'Cut' button.

thanx,
bhuvan.

dogbear
May 3rd, 2000, 07:01 AM
Agniputhran,

More information is needed about this ProgressMonitor Dialog you need help on.

What do you want to do?
Do you want to capture window-closing events?
What do you mean when you say 'Cut the Dialog'?
Is the ProgressMonitor not stopping when you try to kill the dialog?

Regards,
dogBear

agniputhran
May 3rd, 2000, 07:24 AM
sorry. i got the naming wrong.

I meant the dialog closing event.
When i press the 'close dialog' with the 'X' button (as in windows),
the dialog closes, but it is not asserted as anything.

I want it to report a 'Cancel' operation even if the 'X' is used to close the dialog.

If 'X' is pressed, the dialog is closed, but the background task goes on.

regards.
bhuvan.

dogbear
May 3rd, 2000, 08:10 AM
Agniputhran,

To recap:
The Cancel button works perfectly but the Windows Kill button doesn't.

Without the code you are using, I can only guess at this point.
What I can tell you is that there is a "Window-closing" event that is fired whenever the window is dismissed. Whatever code you wrote that the Cancel button executes when pressed is the same code you want called when the "Window-closing" event is fired.

To quickly help you with this problem, could you supply sample code and I'll show you what you need to do? It's the fastest way.

Regards,
dogBear

agniputhran
May 3rd, 2000, 11:54 AM
Hi,

Thats exactly what is happening. The Window close
event is not handled properly.

I need the window close event to work same as
the handler for the 'cancel' button.

I am using the javax.swing.ProgressMonitor class
for doing this.

Here is the code.


...
Timer tim = new Timer ( 500, this );
WorkerThread th = new WorkerThread();
th.start();
ProgressMonitor pm = new ProgressMonitor ( ... );
tim.start();
...



actionPerformed () // called by timer every 500ms
{
//get current state from thread.
// update ProgressMonitor with current state.
if ( pm.isCanceled() )
{
tim.stop(); // stop the timer which does checking.
pm.close(); // close the dialog
th.interrupt(); // stop the thread
}
}





hope this helps.

thanx,
bhuvan.