title: Calculate FPS in Java Game
body: <p>Yesterday I wrote a Thread addressing how my game loop ran (in java) and how it works.</p>
  
  <p>My game loop works completely, and I know why, but now I just wan't to know how to calculate FPS (Frames Per Second) and print it out every second.</p>
  
  <p>I got a response yesterday about this, but he/she explained it in words and I couldn't understand it.</p>
  
  <p>If anyone could help me (with a code example? :D) that would be great.</p>
  
  <p>Here is my game loop:</p>
  
  <pre><code>        while (running) {
  
          start = System.nanoTime();
  
          update();
          draw();
          drawToScreen();
  
          elapsed = System.nanoTime() - start;
  
          wait = targetTime - elapsed / 1000000;
          if (wait &lt; 0) {
              wait = 5;
          }
  
          try {
              Thread.sleep(wait);
          } catch (Exception e) {
              Game.logger.log("ERROR! Printing Stacktrace...");
  
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>ALSO:</p>
  
  <p>In my JFrame when ever I call setName(string) it never works/updates on the Frame - Link me to a thread?</p>