public void calculateFPS() {  
		if (startTime == 0) {   
			startTime = System.currentTimeMillis();
		}  if (framesDrawn > 30) {   
			long delay = System.currentTimeMillis() - startTime;
			averageFPS = (int) ((framesDrawn) / (delay / 1000f));
			startTime = System.currentTimeMillis();
			int timePerFrame;

			if (averageFPS != 0) {
				timePerFrame = 1000 / averageFPS;
			} else {
				timePerFrame = 100;
			}
			frameWaitTime = 17 - timePerFrame + frameWaitTime;
			framesDrawn = 0;
		}
	}