• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

TimerTask and Schedule

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have a small program which uses a timer and timer task package.. the program works fine.. but the problem is that as the time elapses i want to show the hour minutes and seconds .. is there a way to print it..
The program is as follows...
===========================================================================
package com.mylib.olrt.Timer;
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();

}
}

}
===========================================================================
package com.mylib.olrt.Timer;

public class Timertest
{
public static void main(String args[])
{
TimerBean tb=new TimerBean(5);
System.out.println("TAsk Scheduled!");
}

}

=============================================================================


Thank you
Regards
[ April 05, 2006: Message edited by: Ranganath .S.Junpal ]
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, you will have to code it. Currently, you are using Timer to schedual a single event at a particular time. You will now have to schedule a repeating event, every second or so. This new event will now simply print the interium results, if the final time haven't been reached. And do what it did before, if the time has been reached (just don't forget to cancel the event).

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic