怎么在子类中消耗掉父类中定义的某个事件?
子类中怎么把父类注册的监听器在子类中取消,不发生作用,怎么在子类中消耗掉父类中定义的某个事件
//在子类中怎么把父类中的某个事件消耗掉,如下
//A.java
import javax.swing.*;
import java.awt.event.*;
class B extends JButton{
public B(){
super("Button");
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
System.out.println("Pressed");
}
});
}
}
class A extends B{
A(){
//在这里怎么把父类B中的Pressed事件消耗掉
//使A的实例在点击时不打印 "Pressed"
}
public static void main(String[] args){
JFrame frame=new JFrame();
frame.setSize(320,240);
A a=new A();
frame.getContentPane().add(a);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}