Jump to content

2 options

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
MojoMonkey

MojoMonkey

    Newbie

  • Members
  • Pip
  • 4 posts
If I need to let the user choose between 2 options.. how would it be done?

Example: "Do you know what time it is?". And then I could accept two answers, either yes or no.

Sorry for explaining this terribly.:o

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
[highlight="Java"]JOptionPane optionPane = new JOptionPane(
"Do you what what time it is?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);[/highlight]

#3
MojoMonkey

MojoMonkey

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks for the fast reply. Could I then use that input? Say in an if statement?

Anyway of doing it without the JOptionPane. Would using booleans be possible?

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

MojoMonkey said:

Thanks for the fast reply. Could I then use that input? Say in an if statement?
Yes, its been a while so I'm not sure if this is the exact syntax:
[highlight="Java"]int value = ((Integer)optionPane.getValue()).intValue();
if (value == JOptionPane.YES_OPTION) {
//Yes!
} else if (value == JOptionPane.NO_OPTION) {
//No!
}[/highlight]

Sun has a great tutorial on JOptionPane's: How to Make Dialogs (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)

MojoMonkey said:

Anyway of doing it without the JOptionPane.
I'm sure there is, but they require more code, and you would just be reinventing the wheel.