📄 delayedtyper.java
字号:
public class DelayedTyper implements Command
{
private long itsDelay;
private char itsChar;
private static ActiveObjectEngine engine = new ActiveObjectEngine();
private static boolean stop = false;
public static void main(String args[]) throws Exception
{
engine.addCommand(new DelayedTyper(100,'1'));
engine.addCommand(new DelayedTyper(300,'3'));
engine.addCommand(new DelayedTyper(500,'5'));
engine.addCommand(new DelayedTyper(700,'7'));
Command stopCommand = new Command()
{
public void execute() {stop=true;}
};
engine.addCommand(new SleepCommand(20000,engine,stopCommand));
engine.run();
}
public DelayedTyper(long delay, char c)
{
itsDelay = delay;
itsChar = c;
}
public void execute() throws Exception
{
System.out.print(itsChar);
if (!stop)
delayAndRepeat();
}
private void delayAndRepeat() throws CloneNotSupportedException
{
engine.addCommand(new SleepCommand(itsDelay,engine,this));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -