如何在Java中调用一个方法,每一次毫秒 [英] How to call a method once per ms in Java
问题描述
您好。 我希望在Java中的功能,可自动调用。
HI. I want a function in java that automatically called.
例如文,我们使用时间
类像吹
for example wen we use Time
class like blew
在 actionperformerd()
函数调用每一个1秒。
the actionperformerd()
function call every 1second.
Timer time = new Time(10,this);
.
.
.
public void actionperformed()
{
timer.run;
//i want move a pic every 1millisecond.
}
我的问题是,定时器
类只接受int值,它的最小
为1秒,我想调用的actionPerformed每隔1毫秒。
my problem is that Timer
class only accept int value and it's minimum
value is 1 second and i want call actionperformed every 1 millisecond.
推荐答案
Java的<一个href="http://download.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html#schedule%28java.util.TimerTask,%20long%29">Timer在接受参数毫秒。所以,你可以做
Java Timer accepts milliseconds in parameters. So you can do
new Timer().schedule(new TimerTask() {
public void run() {
// do stuff
}
}, 1, 1);
不过,有实时功能与毫秒precision您可能需要切换到C。
But to have real-time functionality with milliseconds precision you may need to switch to C.
这篇关于如何在Java中调用一个方法,每一次毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!