实现ActionListener接口  int delay = 1000; //milliseconds
  ActionListener taskPerformer = new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
          //...Perform a task...
          this.increasesecond();
      }
  };
  new Timer(delay, taskPerformer).start();

解决方案 »

  1.   

    对不起,我是java的初学者,不知道你说的实现ActionListener接口具体怎么写?
    你能否给我写详细一点,十分感谢。  题目是这样的:
     使用javax.swing.Timer类对象timer,设置0。5秒触发一个动作事件,执行date3对象中的
    increaseDay()方法。
      

  2.   


    class wux extends TimerTask{
      public void run(){
        System.out.println("hello");
      }
     }new Timer().schedule(new TimerTask(),1,1000);
      

  3.   

    我给了两种形式,你自己喜欢哪种就用那个吧!
    class yourclass implement ActionListener{Timer time1,time2;
    time1=new Timer(1000,this);
    time2=new Timer(2000,new Boy());//boy对象作计时器的监视器
    ...... time1.start();time2.start();
      public void actionPerformed(ActionEvent e)
    {text1.append("欢迎光临"+"\n") ;
            }
      }
    }
      class Boy implements ActionListener
        {  public void actionPerformed(ActionEvent e)
    {TimeWin.text2 .append("欢迎光临"+"\n") ;
            }
        }