6-2 回调

package interfacepage;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

public class TimerTest implements ActionListener {

    
    /**
     * 回调
     * 
     * ActionListener 监听,回调actionPerformed方法
     * 
     * Timer 定时
     * 
     */
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        System.out.println("listener");
        Toolkit.getDefaultToolkit().beep();
    }

    /**
     * @author:lixh
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ActionListener listener = new TimerTest();
        Timer t =  new Timer(1000, listener);
        t.start();
    }

}

 

posted @ 2018-01-09 21:11  aLa神灯  阅读(79)  评论(0编辑  收藏  举报