28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Controlling Your Action Figure: Implementing <strong>Java</strong> Event Handlers and Using Lambda Expressions<br />

Testing the Game Play Button: Making Sure Your Code Works<br />

Use the Run ➤ Project (or the Run icon at the top of the IDE that looks like a video play transport button) to<br />

launch your InvinciBagel game and click on the PLAY GAME Button on the bottom left of the window. As you<br />

can see in Figure 9-3, the screen turns white because the two ImageView image plates are not visible anymore<br />

and your white background color is shining through! You will notice if you click on the other three Button<br />

controls that they do not work anymore. Actually they are working, but they are not visible anymore, so the UI<br />

design now seems to be broken!<br />

Figure 9-3. Run the Project, and test the PLAY GAME Button to reveal white background<br />

So now we have an ability to see what we are doing going into our game play design chapters, which are the<br />

next eight in the book. All that we have to do now is to fix (or rather upgrade) the other three Button controls event<br />

handling structures to include method calls to make sure that the ImageView Node objects are visible so that they can<br />

show the image content that we want them to display to our players. Let’s take care of this next, since we are working<br />

on the Button UI design for our InvinciBagel game, and then we can take a look at the new <strong>Java</strong> 8 lambda expressions.<br />

Upgrading the Other UI Button Code: Making ImageView Visible<br />

Let’s add a couple of lines of code to each of the three existing Button event handling structures that will make sure<br />

that both ImageView image plates are set to be visible whenever these Button control objects are clicked. The reason<br />

that we need to put this code into each of the three other UI Button event handling structures is because we do not<br />

know what order the user will click on the Buttons, so we need to put these statements into each Button event handler.<br />

If the ImageView Node objects are already set as visible when these statements are triggered, then they will simply<br />

remain visible, because they were already previously visible! The <strong>Java</strong> method calls will look like the following:<br />

splashScreenBackplate.setVisible(false);<br />

splashScreenTextArea.setVisible(false);<br />

As you can see highlighted in Figure 9-4, I’ve installed these (identical, except for the Image object that they<br />

reference) two statements inside of the other three Button event handling structures. These statements can go either<br />

before or after the existing method calls inside each of these .handle() methods.<br />

190<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!