我有一个类Game
和一组按钮buts
,我想在fun(i,j)
单击任何 buts[i][j] 时调用 Game 类上的函数,我试过这样:
buts = new JButton[Setting.length][Setting.width];
Game game = new Game(setting);
int hgap = 4, vgap = 4;
panel = new JPanel(new GridLayout(Setting.length, Setting.width, hgap, vgap));
for (int i = 0; i < Setting.length; i++) {
for (int j = 0; j < Setting.width; j++) {
//JButton btn = new JButton();
buts[i][j] = new JButton();
buts[i][j].setText(String.valueOf(j));
setColor(buts[i][j], Game.cells[i][j].getColor());
buts[i][j].addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonActionPerformed(evt);
}
});
panel.add(buts[i][j]);
}
}
private void buttonActionPerformed(ActionEvent evt) {
}
但我怎样才能将 i,j 发送到函数buttonActionPerformed
?