This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to make JButtons working together? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to make JButtons working together?" Watch "How to make JButtons working together?" New topic
Author

How to make JButtons working together?

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,
How is possible to make JButtons who have same ImageIcon and are consecutive to change for example image when you click one of them?
Consecutive i mean(1s are JButtons with same image):

0000000
0010000
0010010
0000010
1000010
0000000

or

0000000
0000000
1111000
0000000
0001100
0000000
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

I don't know where you're stuck (since you didn't tell us!) all I can so is suggest some tutorials.
http://download.oracle.com/javase/tutorial/uiswing/components/button.html
http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html
http://download.oracle.com/javase/tutorial/uiswing/components/icon.html


luck, db
There are no new questions, but there may be new answers.
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

I didnt start coding yet, im just thinking it. I have stuck at the point how to make those JButtons "group"
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 143

What you want to do here seems like a finite state machine to me, so: yup, it's possible.
If you want to change the buttons which have the images randomly it's a bit less complicated.


Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to make JButtons working together?