title: creating new array when adding/deleting elements?
body: <p>Good Evening. I am working on a program thats similar to the old game LiteBrite, where you place colored pegs on a panel and it lights up. In my program, it works similar in that when you click on the panel, it will create a new Ellipse (which ive named ColorEllipse that has specifications for location, size, and color) and that it will store it to be saved. Currently it is as an arraylist but i need it to be in a regular array. I am told the way that would be to make a new array, and copy all the contents of the old array into the new array. Now currently i use an arraylist, but unforutnately this program has specifications where we need to use a regular Array.</p>
  
  <hr>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.MouseEvent;
  import java.lang.reflect.Array;
  import java.util.ArrayList;
  
  public class LiteBritePanel extends javax.swing.JPanel{
      private final static int OFFSET = 5;
      private static int LINE_WIDTH = 2;
      private static int CELL_WIDTH = 25;
  
  
      public ArrayList &lt;Colorable&gt; _circles; // where ColorEllipses will be stored
      private ButtonPanel controlpanel; // used to set the color of peg that will be placed
  
      public LiteBritePanel() {
          this.setBackground(java.awt.Color.black);   
  
          _circles = new ArrayList&lt;Colorable&gt;();
  
          controlpanel = new ButtonPanel(this);
          this.addMouseListener(new MyMouseListener(this));
          this.add(controlpanel);
      }
  
      public void paintComponent(java.awt.Graphics aPaintBrush) {
          super.paintComponent(aPaintBrush);
          java.awt.Graphics2D pen = (java.awt.Graphics2D) aPaintBrush;
  
          java.awt.Color savedColor = pen.getColor();
          pen.setColor(java.awt.Color.black);
          for (int ball=0;ball&lt;_circles.size();ball++)
              if(_circles.get(ball).isEmpty())
                  return;
              else
                  _circles.get(ball).fill(pen);
          pen.setColor(savedColor);
          this.repaint();
      }  
  
  
      public void mouseClicked(java.awt.event.MouseEvent e){
          boolean foundSquare = false;
  
          for (int ball=0; ball &lt; _circles.size() &amp;&amp; !foundSquare; ball++){
              if (_circles.get(ball).contains(e.getPoint()) == true){
                  foundSquare = true;
                  _circles.remove(ball);
                  this.repaint();
              }
          }
      }
  
      private class MyMouseListener extends java.awt.event.MouseAdapter {
          private LiteBritePanel _this;
          public MyMouseListener(LiteBritePanel apanel){
              _this = apanel;
          }
  
          public void mouseClicked(java.awt.event.MouseEvent e){
              _circles.add(new ColorEllipse(controlpanel.getColor(), e.getPoint().x - (e.getPoint().x%CELL_WIDTH), e.getPoint().y - (e.getPoint().y%CELL_WIDTH), CELL_WIDTH-3,_this));
              _this.requestFocus();
              boolean foundSquare = false;
              for (int ball=0; ball &lt; _circles.size() &amp;&amp; !foundSquare; ball++){
                  if (_circles.get(ball).contains(e.getPoint()) == true){
                      foundSquare = true;
                                  // code for removing ball if one is placed
                      _this.repaint();
                  }   
              }
              }
          }       
      }`
  </code></pre>
  
  <hr>
  
  <p>Now currently it is set as an Arraylist, but I need it to be in a regular array per this specification. then when the panel is clicked on, it adds a new ColorEllipse into that Array at that specific location (and repaints as necessary for it to show up). A later part of the program would be when i touch a peg thats already placed, it removes it, but thats for another time. right now I need to know how to increment sizes of the array and copy its contents into it. Would anyone be able to tell me what I should change?</p>