Datasets:
ArXiv:
License:
File size: 1,520 Bytes
c574d3a |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package SimpleSlot;
/**
* Created by Administrator on 2017/6/19.
*/
public class RemoteSlot
{
private Command[] onCommands;
private Command[] offCommands;
private Command undoCommand;
public RemoteSlot(int slotNum)
{
onCommands = new Command[slotNum];
offCommands=new Command[slotNum];
Command noCommand = new NoCommand();
for (int i = 0; i < slotNum; i++)
{
onCommands[i] = noCommand;
offCommands[i] = noCommand;
}
undoCommand = noCommand;
}
public void setCommand(int slot, Command on, Command off)
{
if(slot<0||slot>onCommands.length-1)
{
System.out.println("插槽位置错误");
return;
}
onCommands[slot]=on;
offCommands[slot] = off;
}
public void onButtonWasPress(int slot)
{
if(slot<0||slot>onCommands.length-1)
{
System.out.println("插槽位置错误");
return;
}
onCommands[slot].execute();
undoCommand = onCommands[slot];
}
public void offButtonWasPress(int slot)
{
if(slot<0||slot>offCommands.length-1)
{
System.out.println("插槽位置错误");
return;
}
offCommands[slot].execute();
undoCommand = offCommands[slot];
}
public void undoButtonWasPress()
{
System.out.println("正在撤销上一个操作");
undoCommand.undo();
}
}
|