If I have a question like
someMethod(JOptionPane.showConfirmDialog(null, "Are you enrolled in a University?"));
and I want to pass the answer "yes" or "no" to a method...what parameter should that method be accepting? I thought it would be boolean (yes is true, no is false) but I guess I was wrong and a bit of amateur thinking. Do the yes and no answers have a int value then?
I hope my question makes sense.
JOptionPane.showConfirmDialog() returns an int
value which is interpretted into predefined values such as JOptionPane.YES_OPTION
and
JOptionPane.NO_OPTION
. If you want to use the result directly you would have to have a method such as:
void someMethod(int dialogResult)
It will return an int
which represents which button was pressed. Run the code without the method call, and see what order the buttons are in ('Yes No Cancel' or whatever). If you hit yes in that example, it'd return 0, No would return 1, and Cancel 2 (closing the dialog returns -1). It's simply returns the index starting from 0.
See JavaDoc for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With