Well I considered two ways of seeing things may be there are there more .....
The first:
You set an attribute your class Frame, JButton matrix table in the following way ....
Code:
JButton [] [] mButtons = new JButton [5] [5];
Your class JFrame implements ActionListener therefore the action performed method you do
Code:
public void actionPerformed (ActionEvent e) (
for (int i = 0; i <mButtons.length i + +) (
for (int j = 0, j <mButton [i]. length j + +) (
if (((JButton) e.getSource ()). equals (mButtons [i] [j])) (
/ / Then you get the position in the table clicked button, simply change the color of the pieces you want in relation to this one.
)
)
)
)
For the second, it is a bit more complex, I also of course the fact that tt is in the former topic, see my last post
But if not for the explanation, each button will have specific attributes that will be her color, and a list of buttons that will change color at the same time it is clicked. This list of buttons will be charged when you initialize your window.
To do this in Java, a bit of inheritance:
Code:
ReversoPion class extends JButton (
private List <ReversePion> mReversePionsVoisins;
/ / Enumeration to indicate the color of the pawn value fonce (clear)
private ColorReversePioin mColorReversePion;
)
The method becomes actionPerformed this "extracted from the other topic:
Code:
public void actionPerformed (ActionEvent pE) (
changeColorReverse ();
changeColorReverseVoisinsColor ();
)
with the methods felt goods:
Code:
public void changeReversepionColor () (
if (mColorReversePion == ColorReversePion.clair) (
mColorReversePion = ColorReversePion.fonce;
setIcon (sImageIconPionFonce);
) Else if (mColorReversePion == ColorReversePion.fonce) (
mColorReversePion = ColorReversePion.clair;
setIcon (sImageIconPionClair);
)
)
public void changeReversePionsVoisinsColor () (
for (ReversePion vReversePionTmp: mReversePionsVoisins) (
vReversePionTmp.changeReversePionCouleur ();
)
)
Bookmarks