• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 23956
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
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic