Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to andomly pick a button in a 4X4 GridLayout  RSS feed

 
Andy King
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys, I am new in Swing. Really need help on this one.
I created a 4X4 buttons
for (int i = 1; i <= 16; i++){
gameButton = new JButton();
gameButton.setPreferredSize(new Dimension(110,110));
gameButton.setBackground(new Color(225,220,175));
gameButton.setEnabled(false);
centerPanel.add(gameButton);
}
Right now all buttons are disabled. I just want to andomly pick one of those
buttons and enable it. Other buttons still preserve disabled. How to do that?
Thank you very much.
 
Andy King
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O. one more thing is
I have to put icon on each disabled button as well as a different icon
on enabled button.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you planning on randomly selecting buttons? Through a user action somewhere else in the GUI? A background thread? Or just when they get created one is selected?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!