• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

confirm dialog not

 
Ranch Hand
Posts: 62
Notepad Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !

 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Notepad Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
reply
    Bookmark Topic Watch Topic
  • New Topic