I'm trying to create a little button game for a school project. What the game is, is there are a couple buttons that every like 3 seconds will flash a color then if you press it when the color is up, it stays that color.
I have all the buttons created and they display just fine. I just need help with the actual handling code.
What I'm getting stuck on
timer = new Timer(length, jButton1ActionPerformed); timer.setInitialDelay(pause); private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jButton1.setBackground(Color.blue); }
Now this isn't my actual game, I'm just trying to get the hang of the Swing Timers
Now that I have the button changing colors this is the code that I tried to get it to stay that color when clicked.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jButton1.getBackground().equals(Color.blue){
jButton1.setBackground(Color.blue);
timer.stop();
}
}