Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the values for JOptionPane showConfirmDialog options?

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.

like image 461
spaz Avatar asked Dec 03 '22 02:12

spaz


2 Answers

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)
like image 176
Reimeus Avatar answered Apr 26 '23 23:04

Reimeus


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.

like image 32
Alex Coleman Avatar answered Apr 27 '23 00:04

Alex Coleman