Analyze the following code. import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); btOK.setOnAction(new EventHandler() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }); Scene scene = new Scene(btOK, 200, 250); primaryStage.setTitle("MyJavaFX"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited JavaFX * support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } } Question 7 options: The program has a compile error because no handlers are registered with btOK. The program has a runtime error because no handlers are registered with btOK. The message "The OK button is clicked" is displayed when you click the OK button. The handle method is not executed when you click the OK button, because no handler is registered with btOK.
Analyze the following code.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Button btOK = new Button("OK");
btOK.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
System.out.println("The OK button is clicked");
}
});
Scene scene = new Scene(btOK, 200, 250);
primaryStage.setTitle("MyJavaFX"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited JavaFX
* support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
Question 7 options:
|
The program has a compile error because no handlers are registered with btOK. |
|
The program has a runtime error because no handlers are registered with btOK. |
|
The message "The OK button is clicked" is displayed when you click the OK button. |
|
The handle method is not executed when you click the OK button, because no handler is registered with btOK. |
Step by step
Solved in 2 steps