In different parts of my code, I will be running a similar variant of:
_grid[4][4].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveBeginningPieceLeft(_square[4][11]);
refreshBoard();
}
});
The only thing that will change is coordinates of _grid. I tried doing something earlier where I made an actionlistener, but eclipse was forcing me to make the integers final. I'm wondering if it is easy to write an addListener method that uses the values of the grid that it is being called on(_grid is an array of JButtons and _square is an array of stacks). So if I called addListener on _grid[2][5], it would just take the coordinates [2][5] from _grid and place in the _square section of the actionlistener. So,
_grid[0][5].addListener();
is the same as
_grid[0][5].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
moveBeginningPieceLeft(_square[0][5]);
refreshBoard();
}
});