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

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?

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");
} 

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

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

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

2 Likes

@terryz

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!