如下这段代码怎么解释?实现什么功能?
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent windowevent)
{
Window window=windowevent.getWindow();
window.dispose();
System.exit(0);
}
});
请解释这段代码的结构?实现的功能?
------解决方案--------------------这是adapterm模式,用内部类快速实现借口的方法.
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent windowevent)
{
Window window=windowevent.getWindow();
window.dispose(); //释放资源
System.exit(0); //退出窗口系统
}
});
------解决方案--------------------WindowAdapter是抽象类,它是专门用于接收窗口事件的抽象适配器,由于抽象类不能被实例化,所以上面的程序中,创建了一个继承于WindowAdapter的匿名内部类