Using mouse button events while developing sketches in the Eclipse IDE

Method addMouseListener() belongs to class Component from package java.awt:
Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Component.html#addMouseListener(java.awt.event.MouseListener)

Processing’s class PApplet used to extend class Applet, which is a subclass of Component:
Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/java/applet/Applet.html

The latest Processing version which it was still so is v3.0a5.

After that version, most we can do is grab a Component instance like this:

import java.awt.Component;

Component win;

void setup() {
  win = (Component) getSurface().getNative();
  println(win); // processing.awt.PSurfaceAWT$SmoothCanvas[canvas0,14,14,100x100]
  exit();
}

Notice however it’s available only when we’re using the JAVA2D default renderer.

4 Likes