Jump to content

Make JButtons working together...?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
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

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

-Michael Sinz

#2
DonCash

DonCash

    Newbie

  • Members
  • Pip
  • 7 posts
?!?! I don't really get what you mean..

#3
SirJames

SirJames

    Newbie

  • Members
  • PipPip
  • 27 posts
Is that Binary ......... (~_^) :confused:

#4
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users