what's wrong with my code??

i calculate my FPS like this


      public void run() {
            int FPS = 43;
            long startTime, deltaTime;
            while (Thread.currentThread() == animate) {
                  // calculating current FPS
                  newTime = System.currentTimeMillis();
                  if (newTime > oldTime+1000) {
                        System.out.println("FPS: " + ticks);
                        lastTicks = ticks; ticks = 0;
                        oldTime = newTime;
                  }
                  ticks++;

                  startTime = System.currentTimeMillis();
                  repaint();
                  deltaTime = System.currentTimeMillis() - startTime;
                  while (deltaTime < (1000/FPS)) {
                        try { Thread.sleep((1000/FPS)-deltaTime);
                        } catch (Exception e) { e.printStackTrace(); }
                        deltaTime = System.currentTimeMillis() - startTime;
                  }
            }
      }

but i got only 34 fps in output
then i change FPS variable to 100, it increase to 43…
what’s wrong with my code???

I calculate my FPS like this and seems to work ok.


int  f = 0;
long t = System.currentTimeMillis();
while (!quit) {

  render();
  
  // Do other stuff like handle inputs etc.
  ...

  // Calculate frames per second.
  f++;
  if (t+1000 < System.currentTimeMillis()) {
    System.out.println("fps : " + f);
    t = System.currentTimeMillis();
    f = 0;
  }
}

There are some hi-res timers included in the lwjgl which may give a more precise timing, but this is a good start.

Regards,

Andy.