private void GameLoop()
    {
        long visualizingTime = 0, lastVisualizingTime = System.nanoTime();
        
       long beginTime, timeTaken, timeLeft;
        
        while(true)
        {
            beginTime = System.nanoTime();
            
            switch (gameState)
            {
                case RUNNING:
                    gameTime = System.nanoTime() - lastTime;
                    
                    game.Update(gameTime, mousePosition());
                    
                    lastTime = System.nanoTime();
                break;
               
                case STARTING:
                    Initialize();
                    LoadContent();

                     newGame();
                break;
                case VISUALIZING:
                    if(this.getWidth() > 1 && visualizingTime > secInNanosec)
                    {
                        frameWidth = this.getWidth();
                        frameHeight = this.getHeight();
                        gameState = GameState.STARTING;
                    }
                    else
                    {
                        visualizingTime += System.nanoTime() - lastVisualizingTime;
                        lastVisualizingTime = System.nanoTime();
                    }
                break;
            }
            
            repaint();
            
           timeTaken = System.nanoTime() - beginTime;
            timeLeft = (GAME_UPDATE_PERIOD - timeTaken) / milisecInNanosec; // In milliseconds
             if (timeLeft < 10) 
                timeLeft = 10; 
            try {
                 Thread.sleep(timeLeft);
            } catch (InterruptedException ex) { }
        }
    }