@Override
    public void run() {
        requestFocus();
        long lastTime = System.nanoTime();
        final double numTicks = 60.0;
        double nanoSeconds = 1000000000.0 / numTicks;
        double delta = 0;
        int frames = 0;
        int ticks = 0;
        long time = System.currentTimeMillis();

        while (running) {
            long currentTime = System.nanoTime();
            delta += (currentTime - lastTime) / nanoSeconds;
            lastTime = currentTime;

            if (delta >= 1) {
                tick();
                ticks++;
                delta--;
            }

            draw();
            frames++;

            if (System.currentTimeMillis() - time > 1000) {
                time += 1000;
                System.out.println(ticks + " Ticks, FPS: " + frames);
                ticks = 0;
                frames = 0;
            }
        }
        stop();
    }