我在看《JAVA编程思想》的多线程一章中好象有!自己找找吧!

解决方案 »

  1.   

    使用java.awt.Robot类有一个delay方法,
    详情请看我的java技术专栏
    www.csdn.net/Author/turbochen
    中的<<Java的秘密:AWT机器人>>
      

  2.   

    java.util.timer, go there and have a look
      

  3.   

    在java中,一般用来计时的方法是两个System.currentTimeMillis()相减,便可以得出所消耗的时间.
    至于延时,我好像没有听说过
      

  4.   

    没有专门的定时器,可以自己实现://define
    interface TimerAble
    {
        void onTimer();
    }
    class Timer extends Thread
    {
        private TimerAble ta;
        private long interval;
        private boolean stop = false;
        public Timer( TimerAble ta,long inerval )
        {
            this.ta = ta;
            this.inerval = inerval;
        }
        protected void run()
        {
           while( stop != true )
           {
               ta.onTimer();
               Thread.sleep( interval );
           }
        }
        public void stop()
        {
            this.stop = true;
        }
        public void start()
        {
            this.stop = false;
            super.start();
        }
    }
    class MyApp extends Object implements TimerAble
    {
        protected void onTimer()
        {
           //The code want to run on timer.
        }
        public static void main( String[] args )
        {
            MyApp app = new MyApp()
            Timer t = new Timer( app,1000 )
            t.start();//begin timer
            //......
            t.stop;//stop timer
        } 
    }
      

  5.   

    没有专门的定时器,可以自己实现://define
    interface TimerAble
    {
        void onTimer();
    }
    class Timer extends Thread
    {
        private TimerAble ta;
        private long interval;
        private boolean stop = false;
        public Timer( TimerAble ta,long inerval )
        {
            this.ta = ta;
            this.inerval = inerval;
        }
        protected void run()
        {
           while( stop != true )
           {
               ta.onTimer();
               Thread.sleep( interval );
           }
        }
        public void stop()
        {
            this.stop = true;
        }
        public void start()
        {
            this.stop = false;
            super.start();
        }
    }
    class MyApp extends Object implements TimerAble
    {
        protected void onTimer()
        {
           //The code want to run on timer.
        }
        public static void main( String[] args )
        {
            MyApp app = new MyApp()
            Timer t = new Timer( app,1000 )
            t.start();//begin timer
            //......
            t.stop;//stop timer
        } 
    }
      

  6.   

    刚才才了一下document
    jdk1.3以后支持这个操作,实现原理和我上面写的差不错。java.util.Timer;   = Timer
    java.util.TimerTask; = TimerAble