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?)
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?
Joined: Jul 05, 2011
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.
Thanks in advance.
Joined: Oct 13, 2005
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.