I want to implement undo and redo operation for my paint application.
I created class which extends from jpanel and here i have arraylist to keep all the elements on my jpanel.
This how it works when i add new element (f.e i draw something with pencil tool):
this.elements.add(new PencilElement(this.tool.getPPoint(), this.tool.getCPoint(), this.tool.getColor(), this.tool.getStroke()));
I want to use another arraylist to keep copy of all elements and when i click "undo" button: -->last element from temporary array list would be removed -->content of base arraylist (in this case "elements" arraylist) would be replaced by this temporary arraylist content.
If you have another ideas, please share
Thanks!