I generally do it like this:
Dialog dlg = new Dialog(this, ...);
Value result = dlg.showDialog();
The Dialog.showDialog()
function looks like this:
ReturnValue showDialog() {
setVisible(true);
return result;
}
Since setting visibility to true on a JDialog is a modal operation, the OK button can set an instance variable (result
) to the chosen result of the dialog (or null
if canceled). After processing in the OK/Cancel button method, do this:
setVisible(false);
dispose();
to return control to the showDialog()
function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…