undocommand.java

来自「《java设计模式》一书的源码」· Java 代码 · 共 29 行

JAVA
29
字号
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 + -
显示快捷键?