title: How to use addMouseListener on the elements of an array of JPanels without adding it to each single element.?
body: <p>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:</p>
  
  <pre><code>panels[0][0].addMouseListener(new MouseAdapter() {
  
          public void mousePressed(MouseEvent e) {
              panels[0][0].setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
          }
  
          public void mouseReleased(MouseEvent e) {
  
          }
      });
  </code></pre>
  
  <p>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?</p>