title: I cannot pull values from an array in a different class
body: <p>The printout of the array lifegrid2 just gives all zeros.  I tested the lifegrid array in MyPanel and that is populating, but the values are pulling through as zeros.  I checked by putting some values in lifegrid2 and they are being wiped, so it is pulling through from MyPanel, but only zeros.  There are no errors being reported.</p>
  <p>I have made a small test program with a 2d array which does pull values through.</p>
  <pre><code>import javax.swing.SwingUtilities;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
     import javax.swing.BorderFactory;
  import javax.swing.JButton;
  
    import java.awt.*; 
  import java.awt.event.*; 
  
  public class SwingPaintDemo3 {
  
  public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              createAndShowGUI(); 
          }
      });
  }
  
  private static void createAndShowGUI() {
      JFrame f = new JFrame(&quot;Swing Paint Demo&quot;);
      f.setPreferredSize(new Dimension(1280,800));
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      f.add(new MyPanel());
      f.pack();
      f.setVisible(true);
      JPanel subPanel = new JPanel();
      JButton start = new JButton(&quot;START&quot;);
      subPanel.add(start);
      start.setPreferredSize(new Dimension(100,50));
      start.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent ae1) {
              System.out.println(&quot;START&quot;);
              int [][][] lifegrid2 = new int [12][12][2];
              int temp;
              
              for (int i=0; i&lt;12; i++) {
                  for (int j=0; j&lt;12; j++) {
              **MyPanel obj = new MyPanel();
              temp = obj.lifegrid [i][j][0];
                  lifegrid2 [i][j][0] = temp;**
                  if (j&lt;11) 
                      {System.out.print(lifegrid2 [j] [i] [0]);}
                  else 
                      {System.out.println(lifegrid2 [j] [i] [0]);}}}
              
              
              
                                          }   
      });
      f.add(subPanel, BorderLayout.EAST);
      
  } 
  
  }
  
  
  
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  </code></pre>
  <p>import javax.swing.JPanel;</p>
  <pre><code>class MyPanel extends JPanel {
  
  public int [][][] lifegrid = new int [12][12][2];
  
  private int squareX = 1280;
  private int squareY = 800;
  private int gridX, gridY ;
  
  public MyPanel() {
  
             
      addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
              squareX = e.getX();
              squareY = e.getY();
                              if ((squareX&gt;50 &amp; squareX &lt;550) &amp; (squareY&gt;50 &amp; squareY &lt;550) ){
                  gridX =(squareX-50)/50+1;
                  gridY =(squareY-50)/50+1;
                  
                  squareX = (squareX -50)/50 * 50 + 50;
                  squareY = (squareY -50)/50 * 50 + 50;
                  System.out.println(gridX + &quot; &quot; + gridY);
                  lifegrid [gridX] [gridY] [0] = 1;
                  
                  repaint(squareX,squareY,50,50);}
              else {
                              }
          }
          });
       
                               }
  
  
  
  
  
  
  
  protected void paintComponent(Graphics g) {
      super.paintComponent(g);       
      g.drawString(&quot;This is my custom Panel!&quot;,10,20);
      g.setColor(Color.RED);
      g.fillRect(squareX,squareY,48,48);
      g.setColor(Color.BLACK);
      g.drawRect(squareX,squareY,48,48);
  }  
  }
  </code></pre>