title: Java multiple buttons coordinates
body: <p>I'm new in Java.</p>
  
  <p>I'm making Mines. I'm using GridLayout with paramteres (x_length, y_length). I'd like know which button I pressed -> his coordinates (x,y). But if I type it to listener it gives me error -> change modifier of 'x' to final.
  So my ask is how can I simply get coordinates of buttons?</p>
  
  <p>And I also want to ask how can I simply change size of buttons? setSize does not work for me.</p>
  
  <pre><code>    for (int y = 0; y &lt; y_length; y++)
      {
          for (int x = 0; x &lt; x_length; x++)
          {               
              buttons[x][y] = new JButton("X");
  
              buttons[x][y].addMouseListener(new MouseAdapter()
              {
                  public void mouseClicked(MouseEvent e)
                  {
                      if (e.getButton() == MouseEvent.BUTTON1)
                      {
                          //exception -&gt; Cannot refer to a non-final variable x inside an inner class defined in a different method
                          JOptionPane.showMessageDialog(null, "Left -&gt; " + x + " | " + y);
                      }
                      else if (e.getButton() == MouseEvent.BUTTON3)
                      {
                          JOptionPane.showMessageDialog(null, "Right -&gt; " + x + " | " + y);
                      }
                  }
              });
              mines_array.add(buttons[x][y]);
          }
      }
  </code></pre>