In: Computer Science
A JavaFX UI class has a button named 'btnOk' that needs to call a void method with no parameters named 'displayResults' when it is clicked. Write the complete lambda-expression statement to set up the btnOk event handler to do this.
Please find the code below::
ButtonHandleUsingLambda.java
package gui;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class ButtonHandleUsingLambda extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new
Group(), 450, 250);
Button button = new
Button("btnOk");
GridPane grid = new
GridPane();
grid.setVgap(4);
grid.setHgap(10);
grid.add(button, 0, 2);
button.setOnAction((event) ->
{
displayResults();
});
Group root = (Group)
scene.getRoot();
root.getChildren().add(grid);
stage.setScene(scene);
stage.show();
}
public static void displayResults() {
System.out.println("Called me
?");
}
}