@Override
    public void run() 
    {
        double time = System.currentTimeMillis();
        try 
        {
            isDrawing.acquire();
        } 
        catch (InterruptedException ex) 
        {
            Logger.getLogger(RedrawRoutine.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(-1);
        }
        while (true)
        {
            try {
                //Make sure that if all else fails, you sleep for at least a millisecond
                //to let the other logic run.
                isDrawing.release();
                Thread.sleep((long)(1));
                if (time<FRAME_TIME)
                {
                    Thread.sleep((long)(FRAME_TIME-time));
                }
                //When game logic relenquishes control, move forward.
                isDrawing.acquire();
                
                //Refresh the page, making sure to count how long it takes.
                time = System.currentTimeMillis();
                
                refreshView();
                
                time = System.currentTimeMillis()-time;
                
                //Display the time. Commented out, but you can see how long it takes to
                //render a frame by uncommenting the following line:
                
                //g2d.drawString(""+time, 10, 10);
                
                //Draw the image to the buffer.
                graphics = buffer.getDrawGraphics();
                graphics.drawImage(bufImage, 0, 0, null);

                //I don't know what this is for, but it's important. I
                //got it from sample code online, and still need to figure out
                //what this code's purpose is.
                if(!buffer.contentsLost())
                {
                    buffer.show();
                }
            }
            catch (InterruptedException ex) 
            {
                Logger.getLogger(RedrawRoutine.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }