I am trying to write some internal button classes; since they are going to share a lot of functionality, I derive them from a single superclass. Unhappily, this seems to cause me problems with the MouseClicked method. Here is my code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| class MyButton extends Container implements MouseListener { private Label nameLabel;
public MyButton (String tex) { nameLabel = new Label(tex, Label.CENTER); setLayout(null); addMouseListener(this); }
public void mouseClicked (MouseEvent e) { System.out.println("mouseClicked!"); }
public void mouseEntered (MouseEvent e) { System.out.println("mouseEntered!"); }
public void mouseExited (MouseEvent e) {} public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e) {} }
final class DamageViewButton extends MyButton {
public DamageViewButton () { super("D"); }
public void mouseClicked (MouseEvent e) { System.out.println("I hear ya!"); currModuleViewType = VIEWDAMAGE; updateModuleView(); } } |
When the mouse enters the button, I get the message "mouseEntered" just as I should. But on clicking, I get neither "mouseClicked" nor "I hear ya!" Does anyone know what the problem might be? Should I not overwrite listener-interface methods?