title: When creating objects through iteration, how do I get a specfic object?
body: <p>I got an instance variable of type GRect</p>
  
  <pre><code>private GRect brick;
  </code></pre>
  
  <p>that I create several of, through iteration</p>
  
  <pre><code>private void makeBrickLineX(int x, int y, Color color)
  {
      for (int i = 0; i &lt; NBRICKS_PER_ROW; i++, 
                          x += BRICK_WIDTH + BRICK_SEP)                // Sets the x locations and separation between each brick.
      {                                                
          GRect brick  = new GRect (BRICK_WIDTH, BRICK_HEIGHT);
          brick.setFilled(true);
          brick.setColor(color);
          add(brick, x,y);
      }
  }
  </code></pre>
  
  <p>The problem is, I am creating a "breakout" game, and I need to know when the ball has hit a brick. The code for it is simple, I use a method called getElementAt (balls x &amp; y location) this all works. But there are several bricks, and calling remove on  brick <code>remove (brick)</code>. Only removes one brick in lowermost right corner, so these bricks must not share the same name? What can I do to make it work with all instances of "brick".</p>