How to make main method (or any user defined method) work like greenfoot act method?


1 2 3 | public void act() { } |
1 2 3 | public void act() { } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class Simulation { private boolean active = true ; private long stepDuration = 20 ; private World world; public void run() { long lastCallTime; while (active) { lastCallTime = System.currentTimeMillis(); world.act(); final long timeTillNextStep = lastCallTime + stepDuration - System.currentTimeMillis(); if (timeTillNextStep > 0 ) { Thread.sleep(timeTillNextStep); } } } } |