• Post Reply Bookmark Topic Watch Topic
  • New Topic

TimerTask and Schedule  RSS feed

 
Ranganath .S.Junpal
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just wrote a snippet to schedule for a task. the program works.. but the problem is that i want to show the sec, mins ticking, I dont have any idea about it. If some one knows plz let know.


--------------------------------------------------------------------------
The code is as follows:-

import java.util.Timer;
import java.util.TimerTask;
import java.awt.Toolkit;

public class TimerBean {

Timer timer;
Toolkit toolkit;

public TimerBean(int seconds)
{
timer=new Timer();
toolkit = Toolkit.getDefaultToolkit();
timer.schedule(new schedtask(),seconds*1000);
}

class schedtask extends TimerTask
{
public void run()
{
toolkit.beep();
System.out.println("Time's up!");
timer.cancel();

}
}

}

Thank you
Regards
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try making your timer fire every second and update the screen with current time. Maybe you could compare current time to a target Calendar know when it's done and you want to fire the ultimate event.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!