Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 21 ■ Questions and answers: Finishing the setup Methods and digital audio


Again, use the Run ➤ Project work process and test this new Java code by adding the Answer Button
objects to see whether it gives you the desired result. As you can see in Figure 21-12, the StackPane is
rendering, and all that we need to address is the font family and font size used on the face of the Buttons
so that text is large and readable to the player.


Add a final setFont() method call after each setText() method call to set the font family, in this case a
nice, readable Arial Black Font, as well as the font size. Initially the largest we can fit on this Button size is
30 units, which is fairly large. Inside the setFont() method call, we nest a Font.font() method call, which
creates this Font object, loads it with an Arial Black font, and sets its size to 30. This is shown in the
following Java code and shown highlighted in Figure 21-13:


a1Button = new Button();
a1Button.setText("Answer One");
a1Button.setFont(Font.font("Arial Black", 30 ));
a1Button.setMaxSize(350, 100);
a1Button.setTranslateY(-180);
a2Button = new Button();
a2Button.setText("Answer Two");
a2Button.setFont(Font.font("Arial Black", 30 ));
a2Button.setMaxSize(350, 100);
a2Button.setTranslateY(-60);
a3Button = new Button();
a3Button.setText("Answer Three");
a3Button.setFont(Font.font("Arial Black", 30 ));
a3Button.setMaxSize(350, 100);
a3Button.setTranslateY(60);
a4Button = new Button();


Figure 21-12. Use your Run ➤ Project work process and test your first try at your Q&A hierarchy creation and
rendering

Free download pdf