我想爲我的繪畫應用程序實現撤消和重做操作。使用ArrayList撤消操作
我創建了類從jpanel擴展,這裏我有arraylist保留我的jpanel上的所有元素。
這是如何工作的,當我添加新的元素(FE我畫與鉛筆工具的東西):
this.elements.add(new PencilElement(this.tool.getPPoint(), this.tool.getCPoint(), this.tool.getColor(), this.tool.getStroke()));
我想用另一個數組列表把所有元素的副本,當我點擊「取消」按鈕: - >臨時數組列表中的最後一個元素將被刪除 - >基本數組列表的內容(在本例中爲「元素」數組列表)將被替換爲臨時數組列表內容。
如果您有其他想法,請分享
謝謝!
外觀上沒有任何動作api/java/util/Stack.html – bobbel 2014-10-31 12:12:16
撤消的經典模式 - http://en.wikipedia.org/wiki/Command_pattern – Leo 2014-10-31 12:12:42