invoker.java
来自「程序设计模式java入门源码大全」· Java 代码 · 共 38 行
JAVA
38 行
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 + =
减小字号Ctrl + -
显示快捷键?