title: How to display Java Timer on a separate J Frame Form label?
body: <p>i have a question , i have this timer code in java that when its executed it displays a count down timer on its own JFrame label, what i want to do is to display this timer on another JFrame form label without having to move the code to other classes.</p>
  
  <p>I hope you can help me with this thanks lot guys .</p>
  
  <p>this is the code for the Timer class:</p>
  
  <pre><code>import java.awt.EventQueue;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.Timer;
  
  public class TimerExample extends JFrame {
  
     final JLabel label;
     Timer countdownTimer;
     int timeRemaining = 10;
  
     public TimerExample() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(200, 200);
        label = new JLabel(String.valueOf(timeRemaining), JLabel.CENTER);
        getContentPane().add(label);
  
        countdownTimer = new Timer(1000, new CountdownTimerListener());
        setVisible(true);
        countdownTimer.start();
     }
  
     class CountdownTimerListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
           if (--timeRemaining &gt; 0) {
              label.setText(String.valueOf(timeRemaining));
           } else {
              label.setText("Time's up!");
              countdownTimer.stop();
           }
        }
     }
  
     public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
           public void run() {
              new TimerExample();
           }
        });
     }
  
  }
  </code></pre>
  
  <p>thanks</p>