-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteController.java
More file actions
46 lines (38 loc) · 1.04 KB
/
RemoteController.java
File metadata and controls
46 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Gof.command;
public class RemoteController {
Command[] onCommands;
Command[] offCommands;
//执行撤销的命令
Command undoCommand;
//n:指定了一共有几个命令按钮
public RemoteController(int n)
{
onCommands=new Command[n];
offCommands=new Command[n];
for(int i=0;i<n;i++)
{
onCommands[i]=new NoCommand();
offCommands[i]=new NoCommand();
}
}
//给我们的命令按钮设置我们的命令
public void setCommand(int no,Command OnCommand, Command OffCommand){
onCommands[no]=OnCommand;
offCommands[no]=OffCommand;
}
public void onButtonWasPush(int no)
{
onCommands[no].execute();
//记录按下的按钮,用于撤销
undoCommand=onCommands[no];
}
public void offButtonWasPush(int no){
offCommands[no].execute();
undoCommand=offCommands[no];
}
//执行撤销命名
public void undoButtonWasPush()
{
undoCommand.undo();
}
}