Chapter 14 Flashcards

1
Q
What is the output of the following JavaFX program?
import javafx.application.Application;
import javafx.stage.Stage;
public class Test extends Application {
     public Test() {
          System.out.println("Test constructor is invoked.");
     }
     // Override the start method in the Application class
     public void start(Stage primaryStage) {
          System.out.println("start method is invoked.");
     }
     public static void main(String[] args) {
          System.out.println("launch application.");
          Application.launch(args);
     }
}
A

launch application. Test constructor is invoked. start method is invoked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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 3 and d2 is 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following statements are true?

A Node can be placed in a Pane.
A Node can be placed in a Scene.
A Pane can be placed in a Control.
A Shape can be placed in a Control.

A

A Node can be placed in a Pane.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Analyze the following code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Circle;
public class Test extends Application {
// Override the start method in the Application class
public void start(Stage primaryStage) {
HBox pane = new HBox(5);
Circle circle = new Circle(50, 200, 200);
pane.getChildren().addAll(circle);
circle.setCenterX(100);
circle.setCenterY(100);
circle.setRadius(50);
pane.getChildren().addAll(circle);
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
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

The program has a compile error since the circle is added to a pane twice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To place two nodes node1 and node2 in a HBox p, use ___________.

A

p.getChildren().addAll(node1, node2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To remove two nodes node1 and node2 from a pane, use ______.

A

pane.getChildren().removeAll(node1, node2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To add a node to the the first row and second column in a GridPane pane, use ________.

A

pane.add(node, 1, 0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

To place a node in the left of a BorderPane p, use ___________.

A

p.setLeft(node);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly