Make your own listener type. Your type should implement ActionListener
(and thus the actionPerformed
method), and be constructed with three parameters: the button and the two integers. The reason why you need these three parameters is so that you can pass them to the PosePion
method (which should be capitalized posePion
, by the way).
For example:
class PoseActionListener implements ActionListener {
private JButton button;
private int a, b;
public PoseActionListener(JButton btn, int a, int b) {
this.button = btn;
this.a = a;
this.b = b;
}
@Override
public void actionPerformed(ActionEvent e) {
posePion(a, b, btn);
}
}
Then:
button11.addActionListener(new PoseActionListener(button11, 1, 1);
button12.addActionListener(new PoseActionListener(button12, 1, 2);
Or, even better, create all buttons at once:
for (int i=1; i<=7; i++) {
for (int j=1; j<=7; j++) {
JButton btn = new JButton("Button " + i + ", " + j);
// store the button in an array if you want
btn.addActionListener(new PoseActionListener(btn, i, j);
}
}