title: How do you convert thread.sleep to javax.swing.timer?
body: <p>Is there a way to easily convert thread.sleep to javax.swing.timer?</p>
  
  <p>The reason why I would need to do this, is to stop the user-interface from freezing when you press a button, so that you can implement a pause button.</p>
  
  <p>Code Example:</p>
  
  <pre><code>btnStartTiming.addMouseListener(new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent arg0) {
                  try{
                           inputA = Double.parseDouble(txtEnterHowLong.getText()); //Changes double to string and receives input from user
                          }catch(NumberFormatException ex){                        
                          }
  
              while (counter &lt;= inputA){
                      txtCounter.setText(counter + ""); 
                      try {
                          Thread.sleep(1000);
                      } catch(InterruptedException ex) {
                          Thread.currentThread().interrupt();   
                      }
                      System.out.println(counter);
                      counter++;
                      }
          }
      });
  </code></pre>