public void run() {
        while(true) {
            long then = System.currentTimeMillis();
            for (int j = 0; j < DDT; j++) {
                for (int i = 0; i < agents.length; i++)
                    agents[i].control(agents, null);
                shuffle(agents);
                for (int i = 0; i < agents.length; i++)
                    agents[i].step();
            }
            repaint();
            long interval = (long) Math.floor(1000 * DT * DDT);
            long now = System.currentTimeMillis();
            interval -= now - then;
            if (interval < 0) {
                System.err.println("time overrun");
            } else {
                try {
                    t.sleep(interval);
                } catch(InterruptedException e) {
                    System.exit(1);
                }
            }
            if (threadSuspended) {
                synchronized(this) {
                    while (threadSuspended) {
                        try {
                            t.wait();
                        } catch(InterruptedException e) {
                            System.exit(1);
                        }
                    }
                }
            }
        }
    }