title: Java Action Listener Nested Loop
body: <p>I am doing a battle ship game and I am new to the Java subject. I did a grid layout with a nested loop in order to create 100 JButtons, but I am experiencing difficulty in trying to add an action listener to all buttons. Is there any way of someone to give me a hand ? </p>
  
  <p>I will post the code later on :) </p>
  
  <p>cheers guys.</p>
  
  <pre><code>enter code here
   public Center_Panel() {
      this.setLayout(new GridLayout(1,2));
      JPanel panel1 = new JPanel(new GridLayout(10, 10));
      panel1.setBackground(Color.BLUE);
  
      for (int i = 0; i &lt; 10; i++) {
          for (int j = 0; j &lt; 10; j++) {
          JButton button = new JButton(Integer.toString(i + + j));
          panel1.add(button);
          }
          //grid [i][j] = b;
      }
  
      this.add(panel1);
  
      JPanel panel2 = new JPanel(new GridLayout(10, 10));
  
      panel2.setBackground(Color.GREEN);
      for (int i = 0; i &lt; 10; i++) {
          for (int j = 0; j &lt; 10; j++) {
          JButton button = new JButton(Integer.toString(i + + j));
          panel2.add(button);}
  </code></pre>