Re: JDialog Question...
The following is a short version of my Jdialog...
public class InputDialog extends JDialog
{
private Boolean okButtonPressed_; // true = OK button pressed
/* init here ... */
/*
* OK button even handler
*/
private void okButtonActionPerformed(java.awt.event.ActionEvent
evt)
{
this.setVisible(false);
this.okButtonPressed_ = true;
}
}
This is a method of the class which is calling my InputDialog:
private void cmdUserSettings()
{
InputDialog inputDialog = new InputDialog(null, true);
// if ok button was pressed
if (inputDialog.getOkButtonPressed()) // #####
{ /* ... */ }
else
{ /* ... */ }
if (inputDialog != null)
inputDialog.dispose();
}
The line marked with ##### is sometimes throwing a NullPointerException,
thus indicating that somehow the garbage is destroying inputDialog...
Any suggestions?
Daniel Pitts wrote:
Ramon wrote:
Hi,
I'm trying to make a class that inherits from JDialog. The dialog has
two buttons: Ok and Cancel. When the OK button is clicked, the main
form is trying to read a result that is stored in the dialog's variable.
Question: Is there a safe way how to read a dialog's instance
variable (using a getter) after the dialog is set to invisible (i.e.
this.setVisible(false)) ?
PS: In general I am able to read the dialog's variables but,
apparently, sometimes the dialog is destroyed by the garbage collector...
Thanks.
If you have a reference to the JDialog, then it will not be garbage
collected. Are having a particular problem? What are the symptoms?
Provide an SSCCE if you want to get the most help from this newsgroup.
See <http://sscce.org> if you don't know how or why to provide an SSCCE.