@Override
    public void run() {

        //timer
        long lastTime;
        lastTime = System.nanoTime();

        long timer;
        timer = System.currentTimeMillis();

        final double ns;
        ns = 1000000000.0 / 60.0;

        double delta;
        delta = 0;

        //ups & fps counter
        int frames;
        frames = 0;

        int updates;
        updates = 0;

        requestFocus(); //focus the canvas
        while (running) {
            long now;
            now = System.nanoTime();
            delta += (now - lastTime) / ns;
            lastTime = now;

            //update 60 times per second   
            while (delta >= 1) {
                update();
                updates++;
                delta--;
            }
            render();
            frames++;

            if (System.currentTimeMillis() - timer >= 1000) {
                timer += 1000;
                // System.out.println(updates + " ups, " + frames + " fps");
                frame.setTitle(TITLE + "  |  " + updates + " ups, " + frames + " fps");
                updates = 0;
                frames = 0;
            }

        }
        stop();

    }