Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 17 ■ i3D Game Square SeleCtion: uSinG the piCkreSult ClaSS with 3D moDelS


Remember to double-click the Create method “createSceneProcessing()” in javafxgame.
JavaFXGame option to have NetBeans 9 code a bootstrap method for you. You’ll be replacing the
placeholder Java code with your scene Scene object instantiation and configuration code and then adding
the MouseEvent handling logic after that.
The first thing that you’ll need to do is to open your createBoardGameNodes() method and select
all of the Scene scene object instantiation and configuration Java 9 code, for which there are three Java 9
statements currently; then right-click the selection set and select the Cut option to remove the Java code
from that method body.
Inside of your .createSceneProcessing() method, replace your bootstrap code (unimplemented error
code) by selecting that one line of code and right-click it; select Paste to replace it with the three lines of
code that you “cut” from your createBoardGameNodes() method. Finally, add a line of code at the end of
the method to start to build your Scene object’s event handling; type scene and then a period and then
setOnMouse, which will give you a pop-up helper dialog containing all of the MouseEvent events. The
following is the Java code for the existing statements and an empty event handling lambda expression
infrastructure (for a change), as highlighted in blue in Figure 17-2:


private void createSceneProcessing() {
scene = new Scene(root, 1280, 640, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
scene.setCamera(camera);
scene.setOnMouseClicked(event-> { ... } ); // This is an Empty OnMouseClicked Event Handler
} // Structure is using a Lambda Expression Format


Figure 17-1. Add the createSceneProcessing() method call, after the createBoardGameNodes() method in the
start method

Free download pdf