Chapter 14 Flashcards
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); } }
launch application. Test constructor is invoked. start method is invoked.
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());
}
}
d1 is 2 and d2 is 2, d1 is 3 and d2 is 3
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 Node can be placed in a Pane.
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); } }
The program has a compile error since the circle is added to a pane twice.
To place two nodes node1 and node2 in a HBox p, use ___________.
p.getChildren().addAll(node1, node2);
To remove two nodes node1 and node2 from a pane, use ______.
pane.getChildren().removeAll(node1, node2);
To add a node to the the first row and second column in a GridPane pane, use ________.
pane.add(node, 1, 0);
To place a node in the left of a BorderPane p, use ___________.
p.setLeft(node);
To add two nodes node1 and node2 into a pane, use ______.
pane.getChildren().addAll(node1, node2);