Basic MouseListener Question
Hi, I have a really basic question that I can't find the answer to online. Would anyone mind explaining where my understanding is lacking.
Below is some pseudo code explaining an example of implementing a mouse listener that doesn't work:
Code:
class MainApplet extends JApplet
init() {
add(new MyJComponent())
}
class MyJComponent extends JComponent implements MouseListener
public void mouseClicked(MouseEvent e) {
System.out.println("hello")
}
public void paint(g)
...
Since a component in the applet has a mouse listener I would expect the component to know to watch for mouse events automatically, however it seems that I need to do this:
Code:
class MainApplet extends JApplet implements MouseListener
init() {
MyJComponent c = new MyJComponent()
c.addMouseListener(this)
add(c)
}
public void mouseClicked(MouseEvent e) {
System.out.println("hello")
}
class MyJComponent extends JComponent
public void paint(g)
...
placing the handling of all mouse events in the hands of the applet. I'm sure I must be doing something wrong.
Many Thanks,
James