Re: Stupid dialog closing question
Koos Pol wrote:
...
Is this the way to make windows auto close after pressing a button?
It is one way. It depends on what you want the 'window'
to do after the button is clicked. Here is another example
that might suit the immediate purpose better.
<sscce>
import javax.swing.JOptionPane;
public class FooBar2 {
public FooBar2 () {
String[] options = {"Foo", "Bar", "Too"};
int choice = JOptionPane.showOptionDialog(
null,
options[0] + " & " +
options[1] + " & " +
options[2],
"" + options[0] + options[1] + options[2],
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[1]
);
if (choice<0) {
System.out.println( "No choice made" );
} else {
System.out.println( "choice: " + options[choice] );
}
}
public static void main(String[] args) {
FooBar2 fb2 = new FooBar2();
}
}
</sscce>
Note this example shows how to return data to
the calling process. There are other ways to close
frames and dialogs that might also make sense,
such as adding a WindowListener or calling the
setDefaultCloseOperation method for a frame.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via http://www.javakb.com