Waiting for user response

Hi,

I would like to implement in my code a dialog box that asks the user if he would like to save his work before exiting. This is what I wrote:

Listener exitListener =new Listener(){

publicvoid handleEvent(Event e){

if (!book.isSaved()){

offerToSave();

}

System.exit(1);

}

};

where offerToSave() is a method that opens the dialog box.

The problem is that the System.exit(1) line runs without waiting for the offerToSave dialog to close...

Any ideas on how to fix this?

Thanks very much,

Ron

[875 byte] By [ronEyala] at [2007-10-3 4:17:23]
# 1
Is offerToSave actaully executed?
CeciNEstPasUnProgrammeura at 2007-7-14 22:18:59 > top of Java-index,Java Essentials,Java Programming...
# 2
By the way, using System.exit() to exit an application is pretty much like pulling your PC's power plug - bear in mind that the JVM may run other programs as well that you'll take down with you. Just close the frame, as long as no other threads are running, the app should terminate
CeciNEstPasUnProgrammeura at 2007-7-14 22:18:59 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes, the dialog pops up for half a second but the program exits.And thanks for the advice, I'll change that.
ronEyala at 2007-7-14 22:18:59 > top of Java-index,Java Essentials,Java Programming...
# 4

I thought I might have the offerToSave() method return some value when it's finished, and then put the exit command in a while loop to check if that value is returned yet.

for example:

int value = 0;

...

public void handleEvent(Event e) {

if (!book.isSaved())

value = offerToSave();

else value = 1;

while (value != 1) {}

// do nothing

shell.close();

}

that way the while loop would check over and over until value==1.

But this seems very inefficient and un-elegant.

Is there a better way to do this?

ronEyala at 2007-7-14 22:18:59 > top of Java-index,Java Essentials,Java Programming...