This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JOption showOptionDialog problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JOption showOptionDialog problem" Watch "JOption showOptionDialog problem" New topic
Author

JOption showOptionDialog problem

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Hi everyone:

I am writing a program that requires the use of JOptionPanes.

I do have to admit I am a little rusty because I haven't used it in a bit, so pardon my naivete.

The one pane I want to use is the showOptionDialog. So far it's having a problem with the code I wrote. Here is a snippet of what I have written for you.



What am I doing wrong exactly? How should it be written? I know many things have changed since Java 5. My IDE is still using Java 6 and I am trying to get it to use Java 7 as a default (any idea how to do that?)

Thanks everyone again for your time and help.

S.T.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
I can tell you free what you need to know about changes to option pane since Java 5: nothing.
What goes wrong? In that code snippet, you are simply showing a dialogue. You have got lots of arguments, and you ought to read the API documentation of all those methods, because they are all slightly different, but you are saying that you want a dialogue to appear in the centre of the screen, with various messages, and one or other of your two options pre‑selected. I cannot remember which of the many overloadings you are using.
What you are supposed to get is a return value, so I suggest you start by wrapping that call in a print instruction, and see what you are selecting.
And you should also tell us what goes wrong. If we don't know that, how can we help?
Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
Campbell:

Thanks for the response. Believe it or not, I HAVE read the documentation online about the OptionPane windows. But so far it hasn't helped all that much surprisingly.

Here is the error message I get so far (I am sorry if I didn't give this to you earlier.)


You ARE right about the return value. It was expecting that I do remember. I edited the code. Here it is below:


It still comes up with the same error message above.
Any thoughts?

Thanks in advance.

S.T.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
Don't write such long lines; I have shown you how to break them into shorter lines.
You should do more than assign the return value. Print it out so you can actually see it.
Beware of your IDE; it is obscuring the problem by letting you run the code and throwing an Exception. Try it from the command line and you will get at least two compiler errors, and no code to run. I know because I tried it. One of the errors is caused by your using the wrong syntax for the import statement. The other has to do with how many arguments you supply, and I am not trying to count them
I presume when you went through the API, you found the link to the dialogues section of the Java Tutorials, which tells you lots more about option panes.
 
Don't get me started about those stupid light bulbs.
 
subject: JOption showOptionDialog problem