Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 20 pages
Exam (elaborations)

Java Chapter 15 Questions with Verified Solutions

Document preview thumbnail
Preview 3 out of 20 pages

Java Chapter 15 Questions with Verified Solutions

Content preview

Java Chapter 15 Questions with Verified
Solutions
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<ActionEvent> handler = new EventHandler<ActionEvent>() {
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 ✔️✔️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.


Analyze the following code.


import javafx.application.Application;
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) {
// Create a button and place it in the scene
Button btOK = new Button("OK");
btOK.setOnAction(e -> System.out.println("OK 1"));
btOK.setOnAction(e -> System.out.println("OK 2"));


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

A. When clicking the button, the pr ✔️✔️C. When clicking the button, the program displays OK2.


Which of the following code correctly registers a handler with a button btOK?
A. btOK.setOnAction(e -> System.out.println("Handle the event"));
B. btOK.setOnAction((e) -> System.out.println("Handle the event"););
C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event"));

D. btOK.setOnAction(e -> {System.out.println("Handle the event");}); ✔️✔️A. btOK.setOnAction(e
-> System.out.println("Handle the event"));
B. btOK.setOnAction((e) -> System.out.println("Handle the event"););
C. btOK.setOnAction((ActionEvent e) -> System.out.println("Handle the event"));
D. btOK.setOnAction(e -> {System.out.println("Handle the event");});


Fill in the code below in the underline:


public class Test {

Document information

Uploaded on
March 21, 2025
Number of pages
20
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$12.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KateJones
4.8
(12)
Sold
31
Followers
0
Items
5707
Last sold
1 week ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions