title: Get buttons already added in a JFrame
body: <p>I'm developing a simple 15-puzzle game. I added 16 generated numbered buttons to a JFrame and that was the exercise (University). 
  I'm now trying to go further and make interactions so I need to get all buttons and put them into a 2D vector in order to calculate where user clicks and if and where the cell could "slide", but I don't know how to get them from the Frame.</p>
  
  <p>Here is the generator code:</p>
  
  <pre><code>public void generation(){
      int num;
      Random rand = new Random();
      ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
      for(int i = 0; i &lt; this.getTot(); i++)
          list.add(""+ i);
  
      while(!list.isEmpty()){
          do{                     
              num = rand.nextInt(this.getTot());
          } while (!list.contains("" + num));
  
          list.remove("" + num);
  
          if(num == 0){
              this.add(new Button(" ");
          }
          else{
              this.add(new Button("" + num);                  
          }
      }
  }
  </code></pre>
  
  <p>And here is the constructor:</p>
  
  <pre><code>public Base15(int x, int y){
      this.setSize(WIDTH, HEIGHT);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      this.setLayout(new GridLayout(x, y));
  
      this.x = x;
      this.y = y;
  
      this.generation();
      this.cells = new Button[x][y];  
  }
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>UPDATE: Followed ufis suggestions and had the 2d array done!</p>
  
  <pre><code>for (int row = 0; row &lt; x; row++){
          for (int col = 0; col &lt; y; col++){
              do{                     
                  num = rand.nextInt(this.getTot());
              } while (!list.contains("" + num));
  
              list.remove("" + num);
  
              if(num == 0){
                  cells[row][col] = new Button(" ", sw, label);
                  this.add(cells[row][col]);
  
              }else{
                  cells[row][col] = new Button("" + num, sw, label);
                  this.add(cells[row][col]);
  
              }
          }
  </code></pre>
  
  <p>Thank you all!</p>