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. pane.setOnMouseClicked((e) –> System.out.println(e.getX() + “, ” + e.getY()));
b. pane.setOnMouseReleased(e –> {System.out.println(e.getX() + “, ” + e.getY())});
c. pane.setOnMousePressed(e –> System.out.println(e.getX() + “, “ + e.getY()));
d. pane.setOnMouseDragged((e) –> System.out.println(e.getX() + “, ” + e.getY()));
#
Section 15.9 Key Events
25. To handle the key pressed event on a pane p, register the handler with p using .
a. p.setOnKeyClicked(handler);
b. p.setOnKeyTyped(handler);
c. p.setOnKeyReleased(handler);
d. p.setOnKeyPressed(handler);
#
26. Fill in the code to display the key pressed in the text.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Test extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Pane pane = new Pane();
Text text = new Text(20, 20, “Welcome”);
pane.getChildren().add(text);
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