Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 10 ■ User InterfaCe DesIgn InteraCtIvIty: event hanDlIng anD ImagIng effeCts

Next, let’s copy and paste the helpButton Java statements into the legalButton event handling structure
and then configure these method call parameter areas by using the correct Text, Background, and Image
objects and pixel location values. Again, clear your TextFlow object and then load your TextFlow object
with your copyText and riteText Text objects using the .addAll() method. Next, set the TextFlow container
X,Y pixel location (its position on the screen) using a 200 Integer value for the .setTranslateX() method
call and a 370 Integer value for the .setTranslateY() method call. Load your uiLayout object background
with the Background.EMPTY constant using your .setBackground() method call and then load your
boardGameBackPlate ImageView with your legalLayer Image object by using the .setImage() method call.
This is all accomplished using the following Java code structure inside the .handle() method, as shown
highlighted in the middle of Figure 10-5:


legalButton.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
infoOverlay.getChildren().clear();
infoOverlay.getChildren().addAll(copyText, riteText);
infoOverlay.setTranslateX( 200 );
infoOverlay.setTranslateY( 370 );
uiLayout.setBackground(Background.EMPTY);
boardGameBackPlate.setImage(legalLayer);
}
} );


Figure 10-4. Test your UI Button event handling with the Start Game and Game Rules, switching back and
forth

Free download pdf