usage of JOptionPane.showMessageDialog and showInputDialog

Hi all, a problem here.

Lets say in terms of GUI, I am only allowed to use JOptionPane.showInputDialog and showMessageDialog.

1. The inputDialog also happens to be my menu. It prompts user to key a number. After the user keys in a number, another inputDialog box appears prompting for another input number. I wish to make it such that : Keying in "1" will display whatever I wish to display in a message dialog box. Keying in "2" will RETURN me to the first original inputDialog box, keying in "3 will exit the whole thing.

I am just unsure how to do that. Do I have to use those event handling stuff or whatever?

2. Upon keying in "1" , my message dialog box is displayed. How do I code it such that when the user finish reading the output and upon clicking OK or simply closes the message dialog box, my inputDialog box appears immediately ....

I am just hoping for some brief example or explanation as I am totally unsure this requires event handling or just a series of IF ELSE will suffice. Thank you for your time.

Message was edited by:

Wind_Walker

[1106 byte] By [Wind_Walkera] at [2007-11-27 7:04:07]
# 1
Don't mess with events. Just look at what the JOptionPane returns and act.If your assignment was an exercise in events then you'd be using a button or something simple while you were learning the model.
awyorka at 2007-7-12 18:55:22 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks for replying.But showMessageDialog is modal. I can't do anything until the user clicks on the "OK" or the "X" cancel. sign.If I want the previous inputDialog box to show up immediately after the user clicks OK/X , how do I do it short of using events?
Wind_Walkera at 2007-7-12 18:55:22 > top of Java-index,Java Essentials,New To Java...
# 3

> Thanks for replying.

>

> But showMessageDialog is modal. I can't do anything

> until the user clicks on the "OK" or the "X" cancel.

> sign.

>

> If I want the previous inputDialog box to show up

> immediately after the user clicks OK/X , how do I do

> it short of using events?

I don't understand the question. Since it's modal, execution of the calling program halts when the dialog is called and then resumes at the spot right after the dialog was called when the dialog closes. No events to worry about, just understand the program flow.

I think that the best way for you to understand this is to throw some code together and play with. Once you see it, you'll understand it and go "D'Oh! what was I thinking?"

petes1234a at 2007-7-12 18:55:22 > top of Java-index,Java Essentials,New To Java...
# 4
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
walken16a at 2007-7-12 18:55:22 > top of Java-index,Java Essentials,New To Java...
# 5

you're doing a guessing game app?

here's the basic way to continually display your 'try again' input box.

class Testing

{

public static void main(String[] args)

{

while(true)

{

String input = javax.swing.JOptionPane.showInputDialog("guess a number");

if(input != null && input.equals("0"))

{

javax.swing.JOptionPane.showMessageDialog(null,"You guessed correctly");

System.exit(0);

}

}

}

}

Michael_Dunna at 2007-7-12 18:55:22 > top of Java-index,Java Essentials,New To Java...