How do I implement a simple undo/redo for actions in java?

前端 未结 5 839
旧时难觅i
旧时难觅i 2020-12-15 07:17

I\'ve created an XML editor and I\'m stuck at the last phase: adding undo/redo functionality.

I\'ve only got to add undo/redo for when users add elements, attributes

5条回答
  •  温柔的废话
    2020-12-15 07:51

    I would try to create an Action class, with a AddElementAction class inheriting off Action. AddElementAction could have a Do() and Undo() method which would add/remove elements accordingly. You can then keep two stacks of Actions for undo/redo, and just call Do()/Undo() on the top element before popping it.

提交回复
热议问题