• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to andomly pick a button in a 4X4 GridLayout

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic