JButton onClick change color background
Hey guys,
I have an array of six colors. I also have a button. What I want to do is, everytime the button is clicked, have its background color change to the next index of the array. Once the button has changed to all six colors, I want it to repeat.
Here is the code I have:
Code:
private void gboard_row1_btn1ActionPerformed(java.awt.event.ActionEvent evt) {
Color colors[] = new Color[6];
int i=0;
colors[0] = Color.red;
colors[1] = Color.orange;
colors[2] = Color.yellow;
colors[3] = Color.green;
colors[4] = Color.blue;
colors[5] = new Color(138, 43, 226);
while( i<6 ) {
gboard_row1_btn1.setBackground(colors[i]);
i++;
}
}
My loop is screwed up and I don't know how I would go about implementing a solution for this. Does anyone have any ideas?
Thanks!