Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Java. util. timer;
Import java. util. timertask; public class timerexample
{
/**
* Use of timers in Java
* Time:
*/
Timer localtimer;
Public timerexample (INT seconds)
{
// Create local Timer
Localtimer = new timer ();
// Create local timer task and set the timer-Parameter
Localtimer. Schedule (New localtimertask (), 0, seconds * 1000 );
}
Class localtimertask extends timertask
{
Int bittest = 0 xffffffff;
Int flag = 1;
Int temp = bittest;
// Override the abstract method of timertask
// The run () will be called every per Timer
Public void run ()
{
If (temp <0)
{
System. Out. println (integer. tobinarystring (temp ));
Temp = bittest &(~ Flag );
Flag <= 1;
}
Else
{
System. Out. println ("Time is up .");
Localtimer. Cancel ();
}
}
}
Public static void main (string [] ARGs)
{
New timerexample (1 );
}
}
This article is from the "select" blog, please be sure to keep this source http://programs.blog.51cto.com/785537/258747