同意   beyond_xiruo(希偌) 这么个题目应该自己先实现。
遇到难题再提问。

解决方案 »

  1.   

    我自己写好了,Java怎么实现定时器啊?
      

  2.   

    可是怎么用我不会啊,有个timer,:(
      

  3.   

    我怎么把我要执行的函数的传给这个类,在这个类里怎么做才好?class Runner implements Runnable{

    private boolean timeToStop = false;
    private boolean timeToBreak = false;

    public void run()
    {
    while(!timeToBreak)
    {
    if(!timeToStop)
    {
    continue;
    }
    //My code
    //执行内部指针pp志向的函数
    }
    }

    public void stopRunning()
    {
    timeToStop = true;
    }

    public void breakRunning()
    {
    timeToBreak = true;
    }

    public void setProc(/*传入的函数指针Proc *p*/)
    {
    /*内部指针pp = p*/
    }
    }
      

  4.   

    传入:
    setProc(this);
    接收:
    public void setProc(Runner r) {}
      

  5.   

    我太厉害了,我的实现代码和网上的一样,哈哈:)
    interface TimerListener{
        public void processEvent();
        }    public Class Clock implements TimerListener{
        Clock(){
            Timer t=new Timer(this);    //向Timer类登记
        }
        public void processEvent(){
        //你的事件处理的代码
        }
        }    class Timer extends Thread {    private TimerListener tl;
        Timer(TimerListener tl){
        this.tl=tl;
        }
        public void run(){
        while(true){
        sleep(1000);
        tl.processEvent();
        }
        }
        }