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

Change the object that the .setOnAction() method call is called off of to a1Button and delete the
processing statements inside of this event handling construct to make it into an empty event handler so that
we can build the score processing logic from scratch. The Java code for the event handler will look like the
following, as shown in Figure 22-22:


private void createQAprocessing() {
a1Button.setOnAction(new EventHandler() {
@Override
public void handle (ActionEvent event) {
... // An Empty ActionEvent Handling Structure
}
});
}


The Java code that will be generated by Alt+Enter will be the same empty event handling structure,
using the lambda expression approach, which will remove three of the eight lines of code, or 37.5 percent of
the coding structure.
Your Java 9 code should look like the following, and your resulting lambda expression is shown in
Figure 22-24. Figure 22-23 shows the work process once you invoke the NetBeans Alt+Enter keystroke.
Select the Use lambda expression option, which will execute an algorithm in the NetBeans 9 IDE that will
rewrite the Java code for you and turn it into the shorter lambda expression programming format.


Figure 22-22. Mouse over the event handling structure, and notice NetBeans wants to convert to a lambda
expression

Free download pdf