Pausing a game in a java application
<p>I am trying to add pause functionality to a game. Unfortunately the method I'm currently using causes the program to take no more inputs so I am unable to resume the game.</p>

<p>Here is what I'm currently doing:</p>

<p>a pause button calls:</p>

<pre><code>public void pause(){
    if(data.paused == true){
        data.paused = false;
    }
    else{
        data.paused=true;
        while(true){
            if(data.paused == true){
                try{
                    Thread.currentThread().sleep(100);
                }
                catch(InterruptedException ie){
                    System.out.println(ie);
                }
            }
            else
                break;
        }
        data.paused=false;
    }
  return;
</code></pre>

<p>I then have a TimerTask that I have to deal with:</p>

<pre><code>class aTask extends java.util.TimerTask {
    protected Data data;
    public aTask( Data d ) { data = d; }
    public void run() { 
        try{ 
            if(data.paused){
                try{
                    Thread.currentThread().sleep(100);
                }
                catch(InterruptedException ie){
                    System.out.println(ie);
                }
            }
            else
                data.tick(); 
        } 
        catch( ATCGameOverException e ){ 
            data.gameOver( e.getMessage() );
        }
    }
};
</code></pre>

<p>where tick causes an action in the game every second.</p>

<p>I would think this would allow the game to pause when the button is pressed and then unpause when the button is pressed again, but I would be wrong.  What am I doing wrong?</p>
