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,...
(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 GeometricObjectand implements Colorable. Design another class named Trianglethat extends GeometricObjectand implements Colorable. Implement howToColor inSquareto display the message Color all four sides. ImplementhowToColor inTriangleto display the message Color all three sides. Draw a UML diagram that involves Colorable, Square, Triangle, and GeometricObject. Write a test program that creates...
Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method...
Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease...
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...
Consider a class ‘A’ with a method public static void show( ). A class ‘Derived’ is...
Consider a class ‘A’ with a method public static void show( ). A class ‘Derived’ is the subclass of ‘A’. Is it possible to define the same method public static void show( ) in the Derived class. Why give reasons? Is it run time polymorphism? (0.5 Marks) Is it possible to define the method public void show( ) (non static method) in the Derived class. What will happen and why give reasons?
Write a member method named countMin.  This method is inside the class SingleLinkedList<E>. So it has the...
Write a member method named countMin.  This method is inside the class SingleLinkedList<E>. So it has the direct access to Node<E> class and data fields head, size. This method counts how many times the smallest data item in this SingleLinkedList<E> appears in the list.  It is assumed that the class passed to E implements the Comparable<E> interface. public int countMin() ---------------------- Write a method named endWith.  This method is OUTSIDE the class LinkedList<E>. It takes in two parameters: two LinkedList of Integers named...
Create a class called FileSumWrapper with a method that has the signature public static void handle(String...
Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound). Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. I'm unsure at how to incorporate the FileSum.read() method to even start anything. I also don't know...
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...
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]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT