title: Undo changes in an arrayList
body: <p>I've an ArrayList of Line Objects called 'lines'. I made my own line class to draw lines with some constraints.  It involves selecting two points in a panel and a line is drawn connecting the two points.  Everytime a line is created, it is added to the 'lines'. The lines are drawn in a panel.  </p>
  
  <p>The paint function in my panel looks like this:</p>
  
  <pre><code>   public void paintComponent(Graphics g){      
  
         super.paintComponent(g);
  
         for(final Line r:lines){
  
              r.paint((Graphics2D)g);
  
         }
      }
  </code></pre>
  
  <p>And everytime two points are clicked on the panel, a new line is created.</p>
  
  <pre><code>class Board extends JPanel{
  
   public void placeLine(){
    Point p1,p2;
    JLabel l1,l2;
    ...
    lines.add(new Line(p1,p2,l1,l2));
    this.repaint();
   }
   public void deleteLine(Line l){
    lines.remove(l);
   }
  }
  </code></pre>
  
  <p>I want to create an UndoAbleEdit in this, and everytime i give undo, the undo method must revert to the last action(i.e.creating a line or deleting a line). I've tried undo for events in JTextArea but i couldn't figure out how to build a custom undo for event changes in ArrayLists. Suggest an example for doing this.</p>
  
  <p>And i'm really sorry for not posting it as an SSCCE.. It is a huge project and it is almost impossible to create an SSCCE.</p>