Problem with AWT listener class

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 :


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?

Hm.

There are a lot of tricky bits to making AWT stuff work.

First off I’d do thsi in SWINg. AWT components represent system componentsm sicne what you are trying to do is a “soft component” your really trying to write a SWINg component.

Secondly, Id inherit from JButton since it sets up most everything you want and just go from there.