Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

confirm dialog not  RSS feed

 
Marius Constantin
Ranch Hand
Posts: 62
Java Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Experts !

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
Posts: 53720
127
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marius Constantin
Ranch Hand
Posts: 62
Java Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Ritchie Michael for your detailed answers, it helps a lot a greenhorn. we are luck to have you !

I have tried putting this piece of code on first line of the program as instructed, but it gives me this error :

[error message]

error: ';' expected
import javax.swing.UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

[/error message]

in this message the ^ sign points out to the bracket (

this is my version of Java

java version "1.7.0"
Java(TM) SE Runtime Environment (build pwi3270-20110906_01)
IBM J9 VM (build 2.6, JRE 1.7.0 Windows Server 2003 x86-32 20110810_88604 (JIT enabled, AOT enabled)
J9VM - R26_Java726_GA_20110810_1208_B88592
JIT - r11_20110810_20466
GC - R26_Java726_GA_20110810_1208_B88592
J9CL - 20110810_88604)
JCL - 20110809_01 based on Oracle 7b147

and here is the code again, maybe I did something wrong.

Please advice,
marius

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Randall Twede
Ranch Hand
Posts: 4583
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.swing.UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);


you need to break that up. the compiler is trying to tell you an import statement is just that.

import javax.swing.UIManager;

then inside your main()

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!