日期:2014-05-20  浏览次数:20912 次

java中接口的用法,详细问题请进来看看
在java Swing 中,

ActionListener ac = new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());

}
};
b.addActionListener(ac);
其中b是一个JButton
我想问ActionListener 为什么能new的?是什么意思,能具体详细解释下用法及原理么

------解决方案--------------------
ActionListener  可能是个抽象类后者接口,这样写就是内部类,必须实现抽象方法,否则报错,仅此而已,
不这么写就得这样了,有点麻烦了,例如
ABC implements ActionListener  
{
 ///实现ActionListener  定义的方法,多写了一个类,两者效果一样

}