JButton cb0 = new JButton ();
JButton cb1 = new JButton ();
JButton cb2 = new JButton ();
String array1 = {"yes", "no", "maybe"};
What I'm trying to do over here is add the strings from array1 into the buttons cb0, cb1, and cb2, such that cb0's text will be "yes", cb1's text "no" and so on. How can I do this using a for loop?
I have a very vague idea on how to do this. I can't figure out how to go to the next button using i. My attempt at a concat is shown below. As an example, the first time it would read cb0.setText (array1 [0]);, the next time cb1.setText (array1 [1]);
for (int i = 0; i < 3; i++)
{
cb + i.setText (array1 [i]);
}
Please let me know if I didn't explain it clearly.
Question
vie7now
JButton cb0 = new JButton (); JButton cb1 = new JButton (); JButton cb2 = new JButton (); String array1 = {"yes", "no", "maybe"};What I'm trying to do over here is add the strings from array1 into the buttons cb0, cb1, and cb2, such that cb0's text will be "yes", cb1's text "no" and so on. How can I do this using a for loop?
I have a very vague idea on how to do this. I can't figure out how to go to the next button using i. My attempt at a concat is shown below. As an example, the first time it would read cb0.setText (array1 [0]);, the next time cb1.setText (array1 [1]);
for (int i = 0; i < 3; i++) { cb + i.setText (array1 [i]); }Please let me know if I didn't explain it clearly.
-0
Link to comment
Share on other sites
8 answers to this question
Recommended Posts