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

📄 remotecontrol.java

📁 深入浅出设计模式
💻 JAVA
字号:
package headfirst.command.remote;import java.util.*;//// This is the invoker//public class RemoteControl {	Command[] onCommands;	Command[] offCommands; 	public RemoteControl() {		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;		}	}  	public void setCommand(int slot, Command onCommand, Command offCommand) {		onCommands[slot] = onCommand;		offCommands[slot] = offCommand;	} 	public void onButtonWasPushed(int slot) {		onCommands[slot].execute();	} 	public void offButtonWasPushed(int slot) {		offCommands[slot].execute();	}  	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");		}		return stringBuff.toString();	}}

⌨️ 快捷键说明

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