Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello there am creating a game on Java and I am struck on how I would automatically change my buttons to a different colour

My code is below...


// panel center

for(int x = 0; x < 12; x++)
{
JButton btnx = new JButton();
btnx.setBackground(Color.GREEN);
btn[x] = btnx;
//btn[x].setText("HI THERE"+(x+1));
btn[x].addActionListener(this);
pCentre.add(btn[x]);
}

cPane.add(pCentre,BorderLayout.CENTER);
}

What I have tried:

I have to set the background color to NULL then create timer which would change the button color every 3 seconds
Posted
Updated 2-May-16 20:39pm
v2
Comments
Sergey Alexandrovich Kryukov 2-May-16 14:56pm    
First of all, why? Second of all, why you are not doing what you thing "you have to..."?
Now, "What I have tried" means you show what you have tried, not just mention it.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900