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 options
Started by MojoMonkey, Jan 03 2008 04:55 PM
3 replies to this topic
#1
Posted 03 January 2008 - 04:55 PM
|
|
|
#2
Posted 03 January 2008 - 05:22 PM
[highlight="Java"]JOptionPane optionPane = new JOptionPane(
"Do you what what time it is?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);[/highlight]
"Do you what what time it is?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);[/highlight]
#3
Posted 03 January 2008 - 07:48 PM
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?
Anyway of doing it without the JOptionPane. Would using booleans be possible?
#4
Posted 03 January 2008 - 09:17 PM
MojoMonkey said:
Thanks for the fast reply. Could I then use that input? Say in an if statement?
[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.


Sign In
Create Account

Back to top









