public void run() {
            double begin = 0;
            double end = 0;
            double last = 0;
            final double ratio = 1000 / 60.0;
            double delay = 0;

            try {
                while (true) {
                    begin = (double) System.currentTimeMillis();
                    emulator.doFrame();
                    screen.repaint();
                    end = (double) System.currentTimeMillis();

                    delay = ratio - (end - begin) - last;
                    if (delay > 0) {
                        Thread.sleep((long) delay);
                        last = 0;
                    } else {
                        last = delay;
                    }
                }
            } catch (InterruptedException e) {
                System.out.println("Interrompido! parando emulação.");
            }
        }