I am trying to make a chess program where I have an 8x8 array of JPanels which all require an addMouseListener but in this addMouseListener I need to make use of the index of that array for it to work, like this:
panels[0][0].addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
panels[0][0].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
}
public void mouseReleased(MouseEvent e) {
}
});
Since I have 64 JPanels that means I need to copy this 63 times and possible changes need to be copied as well. Is there any better, more efficient way to achieve this?