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.scene.layout.HBox;
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");
Button btCancel = new Button("Cancel");

EventHandler handler = new EventHandler() {
public void handle(ActionEvent e) {
System.out.println("The OK button is clicked");
}
};

btOK.setOnAction(handler);
btCancel.setOnAction(handler);

HBox pane = new HBox(5);
pane.getChildren().addAll(btOK, btCancel);

Scene scene = new Scene(pane, 200, 250);
primaryStage.setTitle("Test"); // 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);
}
}
```
a. When clicking the OK button, the program displays The OK button is clicked.
b. When clicking the Cancel button, the program displays The OK button is clicked.
c. When clicking either button, the program displays The OK button is clicked twice.
d. The program has a runtime error, because the handler is registered with more than one source.


a. When clicking the OK button, the program displays The OK button is clicked.
b. When clicking the Cancel button, the program displays The OK button is clicked.

Computer Science & Information Technology

You might also like to view...

For readability, most programs __________ the body of a loop.

Fill in the blank(s) with correct word

Computer Science & Information Technology

After a document has been organized in Outline view, it CANNOT be changed to use another view

Indicate whether the statement is true or false

Computer Science & Information Technology

The feature that is a collection of formatting characteristics that can be applied to text or paragraphs is:

What will be an ideal response?

Computer Science & Information Technology

Data is physically transmitted from one computer or terminal to another in the ________ layer.

a. physical b. transport c. application d. terminal e. data link

Computer Science & Information Technology