Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 21 ■ Questions and answers: Finishing the setup Methods and digital audio

Next, let’s tweak the createQAnodes() method body StackPane and Button UI object configurations so
that the Q&A UI Panel appearance is in the very lower-left corner of the gameplay view, out of the way of the
game board squares as much as possible, and so that all Button objects are still relatively large, are uniformly
spaced out, and are using as large (and as readable) a font family and font size as possible.


Tweaking the Q&A Panel: Refining the createQAnodes() Settings


Let’s start adjusting the parameters for the object configuration settings held in the createQAnodes() method
body, starting with the StackPane. We will move it 20 units, from -405 to -385, using the setTranslateY()
method call; decrease the size 40 units, from 400 to 360 , using the setPrefSize() method call; and increase
the height 154 units, from 500 to 654 , also using the setPrefSize() method call. I edited the setText() method
calls to add longer answer placeholders for the Button UI elements, using Answer Choice 1 (through 4)
rather than Answer One (through Four) to better fill the Button with text. I increased the font size another
10 percent to 33 units with the setFont() method call so that I could see how large I could get the text to
be on the Button surface. I increased the Button height 40 percent using the setMaxSize() method call,
increasing the Button height to 140 units from 100 units. This Button height change also required that I
change the Y spacing intervals for the Button spacing over the StackPane, using the setTranslateY() method
call, from -160, -60, 60, and 160 to -240, -80, 80, and 240.
The new (tweaked) Java 9 code is shown here, in the new createQAnodes() method, as well as in
Figure 21-18:


private void createQAnodes() {
qaLayout = new StackPane();
qaLayout.setTranslateX(-250);
qaLayout.setTranslateY(-385);
qaLayout.setBackground(new Background(new BackgroundFill(Color.WHITE,
CornerRadii.EMPTY,
Insets.EMPTY) ) );
qaLayout.setPrefSize(360, 654);


Figure 21-17. Use Run ➤ Project to see whether the camera has changed the Q&A panel layout

Free download pdf