# Processing alternative to inline onclick()

**URL:** <https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179>\
**Category:** Coding Questions\
**Created:** [August 4, 2019, 2:58pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179 "2019-08-04T14:58:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 4, 2019, 2:58pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179/1 "2019-08-04T14:58:30Z")

</div>

```auto
menu = new button({
  x:menuxy[0]+xx,
  y:menuxy[1]+yy-10,
  width:190+12,
  height:30*10,
  id:"menu",
  col:color(255,255,255,20),
  label:"",
  onClick: function(){
    setups();
  }
});

```

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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 4, 2019, 3:12pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179/2 "2019-08-04T15:12:49Z")

</div>

- [Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#registerMethod-java.lang.String-java.lang.Object-](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#registerMethod-java.lang.String-java.lang.Object-)
- [Forum.Processing.org/two/discussions/tagged?Tag=registerMethod()](http://Forum.Processing.org/two/discussions/tagged?Tag=registerMethod())

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [August 7, 2019, 8:41pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179/3 "2019-08-07T20:41:12Z")

</div>

> [@paulgoux](#):
>
> it enables you to assign different functions to different buttons created using the same “class”

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”.

[http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5bang/ControlP5bang.pde](http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5bang/ControlP5bang.pde)

It also has a Behavior abstract class extension mechanism.

[http://www.sojamo.de/libraries/controlP5/examples/use/ControlP5behavior/ControlP5behavior.pde](http://www.sojamo.de/libraries/controlP5/examples/use/ControlP5behavior/ControlP5behavior.pde)

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

[http://www.lagers.org.uk/g4p/ref/classg4p\_\_controls\_1\_1\_g\_button.html](http://www.lagers.org.uk/g4p/ref/classg4p__controls_1_1_g_button.html)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 7, 2019, 8:45pm UTC](https://discourse.processing.org/t/processing-alternative-to-inline-onclick/13179/4 "2019-08-07T20:45:55Z")

</div>

- [Forum.Processing.org/two/discussions/tagged?Tag=addBang()](http://Forum.Processing.org/two/discussions/tagged?Tag=addBang%28%29)
