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();