• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to transfer one arraylist to another and then back to draw it on a canvas  RSS feed

 
Hans Hovan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a program that allows the user to select a color and then draw a circle on a canvas. The circles are object that get added to an arraylist and are all drawn on the canvas until the user clicks undo (which removes the most recently drawn circle) or erase (which removes all of the circles). Everything regarding that works. However, I also have to have it so that if the user clicks erase and then undo all of the circles in the circle arraylist that were just erased must be redrawn. I can't figure out how to do this and would appreciate any suggestions.

As it is now I've tried to make another temp arraylist and I transfer all of the circle arraylist to it prior to removing all of the elements from the circle arraylist. If the user clicks undo after erase then I transfer the temp arraylist back to the circle arraylist and repaint the canvas.

Here is the code I think is relevant..it does everything correctly except redraw all of the circles if erase and then undo are pressed:



I changed the button listener to try and get the erase-undo to work:



Not sure what is going wrong but it only redraws some of the circles, or the circles in the wrong order, etc.
Any ideas on a better way to do this? Thank you.



 
Hans Hovan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved:

This seems to work.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!