Reputation: 451
Okay so I'm designing a gui. Typically I've done GUIs that take a certain set of initial input and then fires off the program to do the work. But now I need something a little different. I need a program that is running, gets to point A, fires off a GUI and hults execution until a check box is selected. Once selected the program takes the input in the GUI and continues execution with the newly created variables from the GUI input.
My question is what is the best way to do this? Event, window, action listeners? This type of thing was easy with javascript and php, however never did it like this before in java. Not sure what to google or where to go from here. Doing my best to google some examples until I get a response here. Thanks all.
I've tried this so far from responses but it throws up a huge giant blob of a mess in middle of screen. Not sure. What the gibberish means, looks like some kind of properties of the radiobuttons. It does function though. It halts execution.
JRadioButton rb1 = new JRadioButton("Modify 1");
JRadioButton rb2 = new JRadioButton("Modify 2");
JRadioButton rb3 = new JRadioButton("Modify 3");
JRadioButton rb4 = new JRadioButton("Modify 4");
JOptionPane.showInputDialog(null, "Please choose Scenario."+rb1+rb2+rb3+rb4,JOptionPane.QUESTION_MESSAGE);
Upvotes: 3
Views: 205
Reputation: 563
You can do it by using JOptionPane.showOptionDialog(...) here's an example:
Object[] senario = {"first", "second", "third", "last"};
int n = JOptionPane.showOptionDialog(null,
"Pick a senario",
"Choose!",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
senario,
senario[0]);
System.out.println("Your choice was: " + senario[n]);
there are other ways, but this is what I would use. No radio buttons though.
Upvotes: 2
Reputation: 10285
As mre said, you create a modal window and pass the program as an argument to the gui. When the gui finishes, it asks the program (which is a variable passed at construction of the modal window) to resume its work.
Upvotes: 3
Reputation: 6516
Regarding the listening portion...
I would use the ItemListener
interface for the part where you halt execution until a specific checkbox is selected. It doesn't look like you'll need any more listeners than that, but if I were you, I would run the program via a Thread
. That way, you can start and stop execution whenever you see fit.
Upvotes: 2
Reputation: 16677
hard to tell... Swing gives you pretty much complete flexibility in what you want to do..
you may be able to get away with a dialog frame as a base window - then add in a progress meter to show where you are, then prompt at the right points in the process.
Upvotes: 2