Trying to write a for loop to insert buttons into the array.
This is the code to create an array that can hold 7 values:
JButton[] buttons = new JButton[7];
String[] buttonText = {"Circle", "Square", "Oval", "Smiley", "Swirl", "Start", "Stop"};
This is the for loop I'm not sure about to fill the array:
int i = 0;
for (int buttons[] = 0; buttons.length(); buttons[i++]) {
JButton addButton = new JButton(buttonText);
}
And this is the foreach loop which accesses each element in the array and adds a listener and adds the buttons to the panel:
for (JButton button : buttons) {
button.addActionListener (listener);
controlPanel.add (button);
}
It comes up with a compile error saying buttons[i++] "is not a statement".