Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What is the output of the following code? import javafx.beans.property.Intege

ID: 3803607 • Letter: 1

Question

1. What is the output of the following code?

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public class Test {
public static void main(String[] args) {
IntegerProperty d1 = new SimpleIntegerProperty(1);
IntegerProperty d2 = new SimpleIntegerProperty(2);
d1.bind(d2);
System.out.print("d1 is " + d1.getValue()
+ " and d2 is " + d2.getValue());
d2.setValue(3);
System.out.println(", d1 is " + d1.getValue()
+ " and d2 is " + d2.getValue());
}
}

a. d1 is 2 and d2 is 2, d1 is 2 and d2 is 3

b. d1 is 1 and d2 is 2, d1 is 3 and d2 is 3

c. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3

d. d1 is 2 and d2 is 2, d1 is 3 and d2 is 3

2. The statement for registering a listener for processing list view item change is ________

a. lv.addListener(e -> {processStatements});

b. lv.getSelectionModel().selectedItemProperty().addListener(e -> {processStatements});

c. lv.getItems().addListener(e -> {processStatements});

d. lv.getSelectionModel().addListener(e -> {processStatements});

3. *Which of the following statements are true?

A source object fires an event.

A handler object fires an event

A handler is registered with the source object for processing the event

Any object such a String object can fire an event

4.Suppose a JavaFX class has a binding property named weight of the type DoubleProperty. By convention, which of the following methods are defined in the class?

public DoubleProperty weightProperty()

public double getWeight()

public DoubleProperty WeightProperty()

public double weightProperty()

public void setWeight(double v)

5. Every JavaFX main class ________.

extends javafx.application.Application

overrides start() method

overrides start(Stage s) method

implements javafx.application.Application

6. Which of the following can be used as a source for a binding properties?

DoubleProperty

IntegerProperty

String

Double

Integer

7. The setOnAction method is defined in ________.

a.Labelled

b. Button

c. ButtonBase

d. Label

e. Node

8. Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter K?


// import javafx classes omitted
public class Test extends Application {
@Override
public void start(Stage primaryStage) {
// Code to create and display pane omitted

pane.setOnKeyPressed(e ->
System.out.print("Key pressed " + e.getCode() + " "));
pane.setOnKeyTyped(e ->
System.out.println("Key typed " + e.getCode()));
}
}

a. Key pressed K Key typed UNDEFINED

b. Key pressed K

c. Key pressed K Key typed

d. Key typed UNDEFINED

9. To add two nodes node1 and node2 into a pane, use ________.

a. pane.add(node1, node2)

b. pane.getChildren().addAll(node1, node2);

c. pane.getChildren().add(node1, node2);

d. pane.addAll(node1, node2);

10. Which of the following statements are true?

a. A Node can be placed in a Scene

b. A Shape can be placed in a Control.

c. A Node can be placed in a Pane

d. A Pane can be placed in a Control.

11. Suppose A is an anonymous inner class in Test. A is compiled into a file named ________.

a. A$Test.class

b.Test$A.class

c. Test&1.class

d. Test$1.class

e. A.class

Explanation / Answer

1.What is the output of the following code?

Ans: c. d1 is 1 and d2 is 2, d1 is 1 and d2 is 3

2. The statement for registering a listener for processing list view item change is ________

Ans: c . lv.getItems().addListener(e -> {processStatements});

3. *Which of the following statements are true?

Ans: A handler is registered with the source object for processing the event

4.Suppose a JavaFX class has a binding property named weight of the type DoubleProperty. By convention, which of the following methods are defined in the class?

Ans: public DoubleProperty WeightProperty()

5. Every JavaFX main class ________.

Ans: overrides start(Stage s) method

6. Which of the following can be used as a source for a binding properties?

Ans: Double Property , Integer Property, Double

7. The setOnAction method is defined in ________.

Ans: c. ButtonBase

8. Suppose the following program displays a pane in the stage. What is the output if the user presses the key for letter K?

Ans: b. Key pressed K

9. To add two nodes node1 and node2 into a pane, use ________.

Ans: c. pane.getChildren().add(node1, node2);

10. Which of the following statements are true?

Ans: b. A Shape can be placed in a Control., c. A Node can be placed in a Pane,

11. Suppose A is an anonymous inner class in Test. A is compiled into a file named ________.

Ans: d. Test$1.class