Can't add a MouseListener to PApplet

365 views Asked by At

I'm currently working on a previously written application using PApplet. I need my class to append a mouse listener to the PApplet. I simply gave my class a reference to its parent PApplet and wrote

parent.addMouseListener(new MouseListener() {
    //Implementation
}

But the parent does not seem to know any thing about my event.

Then, for testing, I tried to add the event directly to the setup method of the PApplet using this code:

this.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent event) {
        System.out.println("Clicked");
    }
});

It gives my the compile error:

"The method addMouseListener(MouseListener) in the type Component is not applicable for the arguments new (MouseAdapter(){})".

I tried the same code with a newly created class extends from PApplet, and it works.

I wonder where could be the error?

0

There are 0 answers