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

📄 remotecontrolwithundo.java

📁 深入浅出设计模式
💻 JAVA
字号:
package headfirst.command.undo;import java.util.*;//// This is the invoker//public class RemoteControlWithUndo {	Command[] onCommands;	Command[] offCommands;	Command undoCommand; 	public RemoteControlWithUndo() {		onCommands = new Command[7];		offCommands = new Command[7]; 		Command noCommand = new NoCommand();		for(int i=0;i<7;i++) {			onCommands[i] = noCommand;			offCommands[i] = noCommand;		}		undoCommand = noCommand;	}  	public void setCommand(int slot, Command onCommand, Command offCommand) {		onCommands[slot] = onCommand;		offCommands[slot] = offCommand;	} 	public void onButtonWasPushed(int slot) {		onCommands[slot].execute();		undoCommand = onCommands[slot];	} 	public void offButtonWasPushed(int slot) {		offCommands[slot].execute();		undoCommand = offCommands[slot];	} 	public void undoButtonWasPushed() {		undoCommand.undo();	}  	public String toString() {		StringBuffer stringBuff = new StringBuffer();		stringBuff.append("\n------ Remote Control -------\n");		for (int i = 0; i < onCommands.length; i++) {			stringBuff.append("[slot " + i + "] " + onCommands[i].getClass().getName()				+ "    " + offCommands[i].getClass().getName() + "\n");		}		stringBuff.append("[undo] " + undoCommand.getClass().getName() + "\n");		return stringBuff.toString();	}}

⌨️ 快捷键说明

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