I've just uploaded my progress into the program. Please have a look and see what is lacking in it. Also, please ignore the lame joke from the strings in it while you're at it. It can be downloaded from this link: http://www.mediafire.com/?n0sp8v22egfsx7t
Note that I used NetBeans to easily make the program.
Edited:
How do I stop the ActionEvent method of a JButton from re-iterating the reading of the first layer of the nested if-else condition once the innermost line or last line of codes is read?
Also, as an additional question, how do I prompt the system to choose between choices thus literally branch out from the other once a choice is given? Apparently what I'm doing was just connect these block of strings together and not branch them out thus appear iterated once a new block of codes is to be displayed in connection to the previous block of code displayed. .
Snippet:
// Strings of text displayed on the JTextArea is shown here
// prompting to choose between two options: example, left or right
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jButton1actionPerformed(e);
}
});
private void jButton1actionPerformed(ActionEvent e)
{
if(jRadioButton1.isSelected())
{
// Display strings of text as response to the choice left
// Another options to choose from here:, example, up or down
JTextArea.setText("You've chosen: " );
JTextArea.append("Now choose between: ");
if (jRadioButton1.isSelected())
{
JTextArea.append("From first choice, choose between: ");
// stop from here
}
else if (jRadioButton2.isSelected())
{
//same as above
}
}
if (jRadioButton2.isSelected())
{
// Same as above
}
}
Use
JTextField.setText("")
whenever you want to clean a text area. Regardind the main issue - Post some code..If I understand what you are asking, this is the whole point of an
if ... else if ... else if ... (etc) ... else
statement. When one of the conditions is matched, none of the other blocks is executed. So it looks like you just need to addelse
s to match yourif
s. For example:However, there is a problem with your code. Why are you checking two times if
jRadioButton1
is selected? After the first if statement, you already know it is selected and don't need to check again.I think if you are asking how to stop the action even once you hit the condition, all you need to do is add a return statement to your code. For example, if button 1 is pushed, display message, then add a return statement, that will result in the code exiting that method and not getting to the other if statement.
Maybe you want to use something like a Hash, or List to store your choices and each time a choice is made, add it to the List. Then you can always find the last choice made by getting our last Element of the list. I'm not real clear on what you are trying to make here, but maybe that will give you some ideas.
I wrote a small program here that has 2 radio buttons and a submit. When you click submit it updates the text in the window based on the radio button selection.
Check out the Java Tutorials on using buttons. Specifically look at the How to use Radio Buttons section to see if that sheds any light on how you would design it.
How to use Radio Buttons