undocommand.java
来自「源码为科学出版社出版的英文<java设计模式>(影印版)所用的所有例」· Java 代码 · 共 31 行
JAVA
31 行
package Undo;
import java.util.*;
public class undoCommand implements Command {
Vector undoList;
public undoCommand(){
undoList = new Vector(); //list of commands to undo
}
//-----------------------------
public void add(Command cmd) {
if(! (cmd instanceof undoCommand))
undoList.add(cmd); //add commands into list
}
//-----------------------------
public void Execute() {
int index = undoList.size () -1;
if (index >= 0) {
//get last command executed
Command cmd = (Command)undoList.elementAt (index);
cmd.unDo (); //undo it
undoList.remove (index); //and remove from list
}
}
//-----------------------------
public void unDo() { //does nothing
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?