title: add mouseListener to an array of JPanels
body: <p>i have an 2D array with JPanels and i want to add a mouseListener in every JPanel in the array so i use 2 for loops to add them ,but i want to pass the variables i used in for loops in every mouseListener but when i try to do that all mouseListener have the same value of the last variables used in the last for loops .so what am i doing wrong ? </p>
  
  <p>here is my code :</p>
  
  <pre><code> for (i=0 ; i&lt;3; i++) {
      for (k=0; k&lt;3; k++) {
         a[i][k].addMouseListener(new MouseAdapter() {
              public void mousePressed(MouseEvent e){
                    temp = a[i-1][k];
                    a[i-1][k] = a[i][k];
                    a[i][k] = temp;
                    //some
                    //code here 
              public void mouseClicked (MouseEvent e) {}
              public void mouseReleased(MouseEvent e) 
                  {
                      invalidate();
                      revalidate();
                      repaint();
                  }
              public void mouseEntered (MouseEvent e) 
                  {}
              public void mouseExited  (MouseEvent e) {
  
                  }
  
  
              });
  
          }
      }
  </code></pre>
  
  <p>I just need to know if there is a way to pass to mouselisteners the variables i,k as arguments to the mouseListener</p>