Processing alternative to inline onclick()

menu = new button({
  onClick: function(){

This is what I am converting from p5.js. Its a call to create a new button with the name “menu”. Now this works fine in p5.js however this does not seem possible in processing. The only functionality which I do not know how to replicate is the
onClick: function(){setups();}
Of course, I know how to create a onClick function, but the beauty of this bit of code, is that it enables you to assign different functions to different buttons created using the same “class” ( I know some might argue, this is not really a class in p5). Anyway is there some sort of processing alternative, I cannot seem to find any documentation which would suggest this, and if not, what would you suggest as an alternative?


ControlP5 has a built in mechanisms for this. The basic mode is callbacks. For example, you write a callback bang(), then create a controller with the callback label “bang”.

It also has a Behavior abstract class extension mechanism.

I believe that G4P does this as well. Both support full event models and control can get pretty fine-grained.