Question

In: Computer Science

A JavaFX UI class has a button named 'btnOk' that needs to call a void method...

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.

Solutions

Expert Solution

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


Related Solutions

(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class...
(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class of a colorable object must implement the Colorable interface. Design a class named Square that extends GeometricObject and implements Colorable. Design another class named Triangle that extends GeometricObject and implements Colorable. Implement howToColor in Square to display the message Color all four sides. Implement howToColor in Triangle to display the message Color all three sides. Draw a UML diagram that involves Colorable, Square, Triangle,...
Assume that Animal is a class that has method void info() that prints "I am an...
Assume that Animal is a class that has method void info() that prints "I am an animal". Classes Bird and Reptile both extend class Animal, and both override method info(). Class Bird implements method info to print "I am a bird", and class Reptile implements method info to print "I am a reptile ". Determine the outcome printed by the following lines of code. Animal animal = new Animal(); animal.info(); //OUTCOME: animal = new Reptile() animal.info(); //OUTCOME: animal = new...
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Write a public class call CountInts. class CountInts has a main method. CountInts must have two...
Write a public class call CountInts. class CountInts has a main method. CountInts must have two methods: count and displayResults. 1. method count takes an array, aa, of ints and counts how many times each integer appears in aa. The integers can only be from 0 to 100 inclusive. 2. method display results displays the results of the count 3. use the template provided. insert your code in the places indicated and don't change anything else. Examples % java CountInts...
In java, (include javadoc comments for each method) design a class named Contacts that has fields...
In java, (include javadoc comments for each method) design a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contacts objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to...
Write a method named area with one double parameter name radius. The method needs to return...
Write a method named area with one double parameter name radius. The method needs to return a double value that represents the area of a circle. If the parameter radius is negative , then return -1.0 to present an invalid value Write another overload method with 2 parameters side1 and side2 (both double) where side1 and side2 represent the sides of a rectangle. The method needs to return an area of a rectangle . If either or both parameters is/...
Write a method named area with one double parameter name radius, the method needs to return...
Write a method named area with one double parameter name radius, the method needs to return a double value that represents the area of a circle. If the parameter radius is negative, then return -1.0 to represents an invalid value write another overload method with 2 parameter side 1 and side 2 (double) where side 1 and side 2 represents the sides of a rectangle. The method needs to return an area of a rectangle. If either or both parameters...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int length, int width)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT