0

Hi!

I would like to add a timer to JTextField. However, my timer does not run. Could you, please, tell me what is wrong in my code. Thanks!

timerTask = new MyTimerTask();
    timer.schedule(timerTask, new Date(0), 5000); // 5 seconds delay
    ...
    private class MyTimerTask extends TimerTask {
         @Override public void run() {
	     SwingUtilities.invokeLater(new Runnable(){
		  public void run() {
		      	    Date date = new Date(0);
		    	    SimpleDateFormat format = new SimpleDateFormat("mm:ss");
		    	    String current_time = format.format(date);
		            taskUptime.setText(current_time);
                  }
             });
         }
    }

Edited by LianaN: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by LianaN
0

Well, I used java.sql.Date instead of java.util.Date. That was the problem:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.