⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invoker.java

📁 程序设计模式java入门源码大全
💻 JAVA
字号:
public class Invoker
{
  Command commands[] = new Command[5];
  int position;

  public Invoker()
  {
    position = -1;
  }

  public void setCommand(Command c)
  {
    if (position < commands.length - 1){
      position++;
      commands[position] = c;
    } else {
      for (int loopIndex = 0; loopIndex < commands.length - 2; 
        loopIndex++){
        commands[loopIndex] = commands[loopIndex + 1];
      }
      commands[commands.length - 1] = c;
    }
  }

  public void run()
  {
    commands[position].execute();
  }

  public void undo()
  {
    if (position >= 0){
      commands[position].undo();
    }
    position--;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -