|
|
----宏命令(Macro Command)测试程序----
// 测试宏命令
public class TestMacroCommand {
public static void main(String[] args) {
Mp3Player player = new Mp3Player("Sony Ericsson");
PlayMusicCommand pm = new PlayMusicCommand(player);
StopMusicCommand sm = new StopMusicCommand(player);
Radio radio = new Radio("Tecsun");
RadioOnCommand ron = new RadioOnCommand(radio);
RadioOffCommand roff = new RadioOffCommand(radio);
FrequencyHigherCommand fh = new FrequencyHigherCommand(radio);
FrequencylowerCommand fl = new FrequencylowerCommand(radio);
FrequencyHigherCommand fh2 = new FrequencyHigherCommand(radio);
FrequencylowerCommand fl2 = new FrequencylowerCommand(radio);
Command[] commands = new Command[] { pm, sm, ron, fh, fh2, fl, fl2, roff };
MacroCommand mc = new MacroCommand(commands);
RemoteControl rc = new RemoteControl();
rc.setCommand(0, mc, mc);
rc.leftButtonPressed(0);
rc.cancelButtonPressed();
}
}
----测试程序运行结果----
Left button [0] is pressed.
Music is playing.
Music is stopped.
Radio is on.
Frequency is set to 100.1
Frequency is set to 100.2
Frequency is set to 100.1
Frequency is set to 100.0
Radio is off.
Cancel button is pressed.
Radio is on.
Frequency is set to 100.1
Frequency is set to 100.2
Frequency is set to 100.1
Frequency is set to 100.0
Radio is off.
Music is playing.
Music is stopped.
-------- |
|