I have this piece of code down below. What I am confused about is why, when the confirmation dialog box appears and I click on the No button, the JVM exits the loop and displays the sum of numbers, but when I select this button using the tab key, the JVM considers this input as YES_OPTION, and the code reacts to this option accordingly.
Thank you so so much !
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 26720
posted
1
I tried some similar code and couldn’t reproduce your error. Now, yes = 0, no = 1 and cancel = 2, which is exactly what I got by running this little program:I suggest you put some debugging print statements into that method, and see what you get.
Michael Dunn
Rancher
Joined: Jun 09, 2003
Posts: 4041
posted
1
the optionPanes have a default button (react to enter key), generally yes/ok/whatever
so even though you've tabbed to 'no' and that button has focus (the dotted square around the text),
hitting enter will fire the default button = ok/yes/whatever.
to fix, add this line as the first line of the program
You should use what Michael said you should use. And realizing that it's executable code, you would naturally put it as the first executable statement.