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);
                  }
             });
         }
    }

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.