pause.java

来自「JAVA 数学程序库 提供常规的数值计算程序包」· Java 代码 · 共 63 行

JAVA
63
字号
package jmathlib.toolbox.time;
   
/* This file is part or MATHLIB */

import jmathlib.core.tokens.*;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.functions.ExternalFunction;

/*
Author: Stefan Mueller (stefan@held-mueller.de) 2003
*/

/**wait for a specified period of time*/
public class pause extends ExternalFunction
{

	public OperandToken evaluate(Token[] operands)
	{

        if (getNArgIn(operands) != 1)
			throwMathLibException("pause: number of arguments != 1");
            

		if (operands[0] instanceof DoubleNumberToken) 
        {
			double pause = (((DoubleNumberToken)operands[0]).getReValues()[0][0]);
        
            try {        
                Thread.sleep((int)(pause*1000));
            }
            catch (InterruptedException e)
            {
            }

		}
        
		return null;
	}
}

/*
@GROUP
time
@SYNTAX
pause(value)
@DOC
Wait for a specified period of time. The command pause(n)
waits for n seconds
@EXAMPLES
<programlisting>
pause(3) waits for 3 seconds
pause(3.5) waits for 3.5 seconds
</programlisting>
@NOTES
Keep in mind that the parsing of the pause(x) command will
also take some time. Therefor the  waiting time will be longer
than expected.
@SEE
tic, toc, date, time

*/

⌨️ 快捷键说明

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