Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 22 ■ SCoring engine: Creating the SCore Ui LayoUt and SCoring the Content

Next, let’s add a scoreCheer Text object declaration to the compound statement at the top of your class.
As you can see in yellow at the top of in Figure 22-18, your compound statement now has two lines, one for
startup (SplashScreen) UI Text objects and a second for Score UI Text objects.


Since you have declared the object, you can add it to the scoreLayout.getChildren().addAll() method
chain, as shown in Figure 22-18, even before you instantiate it and not create an error in NetBeans 9. The
Java statement shown highlighted in light blue at the bottom of Figure 22-18 should look like the following:


scoreLayout.getChildren().addAll(scoreTitle, scoreRight, scoreWrong, scoreCheer);


Copy and paste the scoreWrong Java statements underneath themselves and change scoreWrong to
be scoreCheer. Make the scoreCheer DarkGreen and reduce the font size on scoreRight and scoreCheer to
64 and 56 points so that they fit better in the scoreLayout. Remember, we need room for the numbers that
represent these scores! Since scoreWrong is wider (because of the letters used in the font), I reduced this to
60 points. I spaced out the headings 10 units more in the Y dimension and lined them up on the left by using
the X location of -56, -44, and -2, as shown here in bold and highlighted (the scoreGrade statements at least)
in Figure 22-19:


scoreRight = new Text("Right:");
scoreRight.setFont( Font.font("Arial Black", 64 ) );
scoreRight.setFill(Color.DARKBLUE);
scoreRight.setTranslateX(-56);
scoreRight.setTranslateY( 160 );
scoreWrong = new Text("Wrong:");
scoreWrong.setFont( Font.font("Arial Black", 60 ) );
scoreWrong.setFill(Color.RED);
scoreWrong.setTranslateX(-44);
scoreWrong.setTranslateY( 310 );
scoreCheer = new Text("Great Job!");
scoreGrade.setFont( Font.font("Arial Black", 56 ) );
scoreGrade.setFill(Color.DARKGREEN);
scoreGrade.setTranslateX(-2);
scoreGrade.setTranslateY( 460 );


Figure 22-18. Declare the scoreCheer Text object at the top of the class; then add it to your scoreLayout
SceneGraph branch

Free download pdf