Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Make JButtons working together...?

jbutton

  • Please log in to reply
3 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 22 May 2011 - 10:35 AM

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
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2 DonCash

DonCash

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

Posted 26 May 2011 - 06:52 AM

?!?! I don't really get what you mean..
  • 0

#3 SirJames

SirJames

    CC Regular

  • Member
  • PipPipPip
  • 27 posts

Posted 23 February 2012 - 03:52 PM

Is that Binary ......... (~_^) :confused:
  • 0

#4 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 23 February 2012 - 04:18 PM

You could subclass JButton with MyJButton and give it a special attribute like :
String iconName ...

On creation of each MyJButton object, set the name of the icon. Example: icon1.gif

Then when a button is clicked, you'll have to decide whether or not consecutive buttons have the same icon name.
Example:
//when a button is clicked
this.changeIcon(...);
for( each neighbor of clicked_button )
    if( neighbor.iconName = this.iconName )
        neighbor.changeIcon(...)

If you want to save some time (and NOT extend JButton), you can use JButton's setName(...) and getName() methods.
  • 0





Also tagged with one or more of these keywords: jbutton

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download