1.回调(callback)特定事件发生时 该 采取 什么动作
2.事件监听接口
public interface ActionListener
{
void actionPerfonned ( ActionEvent event ) ;
}
接口应用
class TinePrinter implements ActionListener
{
public void actionPerformed ( ActionEvent event )
{
System out.printlnf At the tone,the time is “+new OateO );
Toolkit.getDefaultToolkit().beep();
}
}
传入的event发生时 执行函数
3.用接口声明新变量
ActionListener listener = new TimePrinter () ;
listener是个event
Timer t = new Timer (1000 , listener) ;
监听事件,每间隔1秒,执行一次函数
4.void beep()发出一声响