# UiBooster library .addButton() redirect to a sub routine on click

**URL:** https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541
**Category:** Libraries
**Created:** [December 27, 2020, 9:40pm UTC](https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541 "2020-12-27T21:40:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![terryz](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@terryz](https://discourse.processing.org/u/terryz)
#### Post date: [December 27, 2020, 9:40pm UTC](https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541/1 "2020-12-27T21:40:00Z")

</div>

Hi, I am using UiBooster by Milchreis. I am having an issue with calling a function using .addbutton() . Relevant code is below; I am getting error “unexpected token: )” on the addButton() to the routine , ()-\>sendData(). I am guessing I am missing a pointer of some kind?

```auto
new UiBooster()
    .createForm(" Brewery Recipe settings ")        
    .addText("Strike Water Temp: ")
    .addText("Mash Temp: ")
    .addText("Mash time: ")
    .addText("Mash Out Temp: ") 
    .addText("Mash Out time: ")
    .addText("Sparge Time: ")
    .addText("Total Boil Time: ")
    .addText("Hop Timing, e.g. 0,30,60: ")
    .addButton("Send Data to Brewery", ()->sendData())
.setChangeListener(new FormElementChangeListener() {

      public void onChange(FormElement element, Object value) {
        if(element.getIndex() == 0) {
          StrikeWaterTemp = element.asString();
        }
        if(element.getIndex() == 1) {
          MashTemp = element.asString();
        }
        if(element.getIndex() == 2) {
          MashTime = element.asString();
        }
        if(element.getIndex() == 3) {
          MashOutTemp = element.asString();
        }
        if(element.getIndex() == 4) {
          MashOutTime = element.asString();
        } 
        if(element.getIndex() == 5) {
          SpargeTime = element.asString();
        }
        if(element.getIndex() == 6) {
          BoilTime = element.asString();
        }
        if(element.getIndex() == 7) {
          HopSchedule = element.asString();
        }
      }
    })
    .run();

void sendData() {
  println("About to send data to controller");
} 

```

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [December 28, 2020, 8:47am UTC](https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541/2 "2020-12-28T08:47:58Z")

</div>

I believe I’ve read somewhere that Processing 4 does allow Lambda expressions. Did you try that?

---

<div class="post-metadata">

### Author: ![terryz](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@terryz](https://discourse.processing.org/u/terryz)
#### Post date: [December 28, 2020, 9:06pm UTC](https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541/3 "2020-12-28T21:06:17Z")

</div>

Turns out all I had to do was to create a Runnable( ) inside the .addButton() function as follows:

```auto
.addButton("Send Parameters to Brewery", "Are You Sure?", 
    new Runnable() {
      public void run() {
        sendData();
      }
    })

```

This solved the problem and allowed me to call my application specific functions. I will be modifying this to make the UI more user friendly.

---

<div class="post-metadata">

### Author: ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)
#### Post date: [March 6, 2022, 10:44pm UTC](https://discourse.processing.org/t/uibooster-library-addbutton-redirect-to-a-sub-routine-on-click/26541/4 "2022-03-06T22:44:25Z")

</div>

@terryz

```auto
new UiBooster()
    .createForm("Brewery Recipe settings ")        
    .addText("Strike Water Temp: ")
    .addText("Mash Temp: ")
    .addText("Mash time: ")
    .addText("Mash Out Temp: ") 
    .addText("Mash Out time: ")
    .addText("Sparge Time: ")
    .addText("Total Boil Time: ")
    .addText("Hop Timing, e.g. 0,30,60: ")
    .addButton("Send Parameters to Brewery", "Are You Sure?", 
    new Runnable() {
      public void run() {
      sendData();
    }}).run();

```

very good!
