java实现一个计时器,可以使用线程的sleep方法,实例如下:public class TestDingShi implements Runnable Thread xc;Dao dao=new DaoImpl();public TestDingShi() xc=new Thread(this);//线程开启xc.start();}public void run() while (true) tryxc.sleep(1000);//睡眠开始计时}catch (InterruptedException e)// TODO Auto-generated catch blocke.printStackTrace();}//TODO定时在此}}}//可以启动一个线程来做时间计算//也可以用timer来实现定时 timer使用wait 我这里用sleep//关键不是用什么而是用线程来解决问题import java.util.scanner;public class test public static void main(string[] args) runnable r = new runnable() final long start = system.currenttimemillis() ;public void run() try while(true) thread.sleep(1000);long now = system.currenttimemillis();if(now-start>=10000) system.out.println("打字时间结束了");system.exit(0);}}} catch (interruptedexception e) // todo auto-generated catch blocke.printstacktrace();}}};system.out.println("可以开始打字了,10秒后就不能打了");scanner s = new scanner(system.in);thread t = new thread(r);t.start();while(s.hasnext()) system.out.println(s.nextline());}}}
当前名称:页面倒计时如何实现,制作倒计时网页
链接地址:http://kswjz.com/article/idigss.html