我的班级实现了 ActionListener。我在下面实现了以下嵌套类:
JMenuItem mntmNew = new JMenuItem("New...");
mntmNew.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
doNew(e); //calls to outer class for cleaner code
}
});
mnFile.add(mntmNew);
JMenuItem mntmLoad = new JMenuItem("Load...");
mntmLoad.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
doLoad(e); //calls to outer class for cleaner code
}
});
mnFile.add(mntmLoad);
//etc. for the rest of the menu system
但是,Eclipse 仍然告诉我,我的类必须实现继承的抽象方法 ActionListener.actionPerformed(ActionEvent e)。不能以这种方式在嵌套类中实现覆盖方法吗?