title: How do I create buttons that reset and pause a timer?
body: <p>How do I make the two buttons that are displayed reset / pause the timer? The timer works but I want to change the code for the buttons so that they will change the timer instead of outputting to the console. Thank you.</p>
  
  <p>CODE:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class createWindow extends JFrame implements ActionListener
  {
  public static void main(String[] args)
  {
      new createWindow();
  }//end main
  
  createWindow()
  {
      super("Frame");
      setSize(400,70);
      setResizable(false);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new FlowLayout());
      show();
  
          final JLabel time = new JLabel("Timer");
          JButton reset = new JButton("Reset timer");
          JButton pause = new JButton("Pause timer");
          reset.setActionCommand("resetClicked");
          pause.setActionCommand("pauseClicked");
          reset.addActionListener(this);
          pause.addActionListener(this);
          add(pause);
          add(time);
          add(reset);
  
      long start = System.currentTimeMillis();
  
      while (true)
          {
              long  timer = System.currentTimeMillis() - start;
              final int seconds = (int) (timer / 1000);
              String display = Integer.toString(seconds);
              time.setText(display);
          }//end while loop
      }//end constructor
  
  @Override
  public void actionPerformed(ActionEvent e) 
  {
      String buttonClicked = e.getActionCommand();
      if(buttonClicked.equals("resetClicked"))
      {
          System.out.println("The reset button was clicked"); //Change to reset timer
      }
      else if(buttonClicked.equals("pauseClicked"))
      {
          System.out.println("The pause button was clicked"); //Change to pause timer
      }
  }//end listener
  }
  </code></pre>