title: Pausing a timerTask
body: <p>I have hit another wall. After getting my key input working, I have been racking my brains for hours, i want to create a pause function, so that if the same key is pressed again the timertask stops running (i.e the game is paused)</p>
  
  <pre><code>JPanel component = (JPanel)frame.getContentPane();
      component.getInputMap().put(KeyStroke.getKeyStroke("SPACE"), "space");
      component.getActionMap().put("space", (new AbstractAction(){
          public void actionPerformed(ActionEvent e){
  
              Timer timer = new Timer();
  
              timer.scheduleAtFixedRate(new TimerTask(){
              public void run(){
                      grid.stepGame();
                  }
              },250, 250);
  
  
  
          }}));
  
  
          }
  </code></pre>
  
  <p>The problem is i cant use a global boolean isRunning var and switch it each time the key is pressed because the timerTask method in a nested class (so the boolean isRunning would have to be declared final to be accessed...). Any ideas on how to detect if the key is pressed again or if the game is already running so i can pause/cancel my timerTask.</p>
  
  <p>Many Thanks Sam</p>