Zeligori
Zeligori

Reputation: 1

In JavaFX I want to have a button appendText and update an ArrayList

I have the following code below:

ArrayList<Double> storeMath = new ArrayList<Double>();

    oneButton.setOnAction(e -> calculator_screen.appendText(listOfButtons[1]));
    oneButton.setOnAction(e -> storeMath.add(1.0));

I want the text to append as well as adding 1.0 to my ArrayList. Unfortunately, it appears that the second lambda is making the appendText to not happen. My goal is to create a calculator so that when you click oneButton it stores 1.0 to the ArrayList and makes 1 appear in my textBox.

Upvotes: 0

Views: 35

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

Do you know that a lambda can contain more than one statement?

oneButton.setOnAction(e -> { 
    calculator_screen.appendText(listOfButtons[1]);
    storeMath.add(1.0;) } );

Upvotes: 2

Related Questions