hi,
i am new to java.Can annybody tell me how to implement confirm box using java.awt package.
i tried by extending dialog class with 2 buttons (buttonSave and buttonDiscard) on dialog box but as ActionEventListener has void return type i could not implement it.
Can anybody tell me any other method.
thanks in advance
Your ActionListeners could set a boolean member variable to false or true,
depending on which button was clicked. Add a nice convenience method to
your class (which extends the Dialog class) that basically does just this:
-
private boolean confirmed= false; // set by the ActionListeners
-
...
-
public boolean isConfirmed() {
-
this.setVisible(true); // this thread will be suspended by the modal dialog.
-
return confirmed;
-
}
In your calling code you just have to do this:
-
if ((new YourDialog(...)).isConfirmed())
-
// user pressed the confirm/ok/save whatever button
Your constructor initializes the entire YourDialog object but doesn't set it
visible yet; that's the task of the isConfirmed() method.
kind regards,
Jos