private static int millis_per_tick = 1;
public void run()
{
// While not stop do
while(true)
{
Thread t = Thread.currentThread();
long startTime, timeTaken;
startTime = System.currentTimeMillis();
act();
timeTaken = System.currentTimeMillis() - startTime;
if(timeTaken < millis_per_tick )
{
try
{
Thread.sleep(millis_per_tick-timeTaken );
}
catch(InterruptedException ex)
{}
}
thread.sleep 方法不接受 double 值,只接受 float 和 integer。但我需要一个低于 1 的值。
在太空
public void act()
{
ListIterator<Body> iterator = bodies.listIterator();
while (iterator.hasNext())
{
Body body = iterator.next();
body.wirkenKraefte();
body.move();
}
spaceGUI.repaint();