JOptionPane Closing Question
I am trying to close a dialog window when a boolean variable in another class changes to false. I use JOptionPane inside of an instance of Dialog. I have tried using hide(), dispose(), and setVisible(false). The problem is that the dialog window does not know to check the variable. Do I need to add some kind of event listener or what? I know this isn't compilable but I think this is a simple question, I must just be overlooking something...
Object[] options ={"Stop"};
JOptionPane optionPane =new JOptionPane("Playing...",
JOptionPane.OK_OPTION,
JOptionPane.INFORMATION_MESSAGE,
dialogIcon,//don't use a custom Icon
options,//the titles of buttons
options[0]);//default button title
Dialog playingDialog = optionPane.createDialog(frame,"Status");
playingDialog.setVisible(true);
//here is what needs to happen when the orhb class sets getPlayState to false
if(!orhb.getPlayState()){
System.out.println("done playing, close window");
setVisible(false);
}
I am not sure what orhb is. But here are several options:
1. Have the option pane poll the state of orhb and close when the state if false
2. Setup the option pane as a listener to "orhb" and have orhb notify it's listeners during a state change.
3. Have orhb close the dialog.
The specifics of your code are going to determine what the best option is.
zadoka at 2007-7-11 23:48:54 >

Here is the code that provoked my answer, above:
playingDialog.setVisible(true); // Note that setVisible is called on the playingDialog
//here is what needs to happen when the orhb class sets getPlayState to false
if(!orhb.getPlayState()){
System.out.println("done playing, close window");
setVisible(false); // Note that setVisible is NOT called on the playingDialog
> Here is the code that provoked my answer, above:
Yea, I thought the same thing at first but then I when I re-read it, I realized that the OP was saying this code:
> //here is what needs to happen when the orhb
> class sets getPlayState to false
> if(!orhb.getPlayState()){
>System.out.println("done playing, close window");
> setVisible(false);
is not being called and the question was where to put it. (Of course once he determines where to put that code he will have to call it on the appropriate object)
zadoka at 2007-7-11 23:48:54 >
