Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 6 ■ Setting Up YoUr Java 9 iDe: an introDUCtion to netBeanS 9


Name the project JavaFXGame, and leave the default Project Location, Project Folder, JavaFX
Platform and Create Application Class settings exactly the way that NetBeans has configured them for
you, as this NetBeans dialog will implement all of your class and package naming conventions for you
automatically, based upon the Project name.
Once you are done, you can click the Finish button, which will tell NetBeans 9 to create the JavaFX game
application for you and open it up in the NetBeans 9 IDE so you can start working on it and learning about
the JavaFX API.
It’s usually a good idea to let NetBeans 9.0 do things for you in the way that they should be done. As
you can see in Figure 6-6, NetBeans creates the logical C:\Users\Walls\Documents\NetBeansProjects\
JavaFXGame folder for your user folder and Documents subfolder using the Project Location and Project
Folder data fields from this dialog.
For the Project Folder data field, NetBeans will (logically) create the subfolder named JavaFXGame. This
will be underneath a NetBeansProjects folder, just as if you had created it yourself, only NetBeans 9 has done
it for you.
For the JavaFX Platform selection drop-down, NetBeans 9 defaults you to the very latest Java 9 JDK,
which is also known as JDK 1.9 and has the latest JavaFX API (which is now an integrated part of the Java 7, 8,
and 9 languages).
We are not going to be implementing a custom preloader project at this point, although if I have time
and any page count left, I may revisit this later during the book. Thus, leave this option unchecked so you
can learn to create this preloader Java 9 project code on your own, rather than having NetBeans 9 do it for
you.
Since you are not creating multiple applications that will share libraries, leave the Use Dedicated
Folder for Storing Libraries check box unchecked, and lastly, make sure that the Create Application Class
is configured correctly. The Java 9 Class should be named JavaFXGame, and it should be contained in the
javafxgame package.
In this configuration, the package path and class name will be javafxgame.JavaFXGame. This will follow
the PackageName.ClassName Java class and package name paradigm, camelCase capitalization, and path,
using your dot notation period character to concatenate the Package Name to the head of the Class Name,
showing where it is kept.
I will go over some of the basic components of the Java code shown in Figure 6-7 during Chapter 7 ,
because we are primarily going to focus on the NetBeans 9.0 IDE and its features during this chapter and
concentrate fully on the JavaFX programming language during Chapter 7 and then again in Chapter 8 as well
when we cover Scene Graph.
As you can see in Figure 6-7, NetBeans has written the package statement, seven JavaFX API package
import statements, and the public class JavaFXGame extends Application declaration; subclassed
your JavaFXGame class, used a JavaFX Application superclass, created a method for startup public void
start(Stage primaryStage), and created a .main() method to manage your main JavaFX thread public
static void main(String[] args).
As you can see in Figure 6-7, NetBeans 9 will color important Java programming statement keywords,
putting keywords in blue, String Objects in orange, internal Java and System references in green, and
comments in gray. Warnings and suggestions inserted by the NetBeans 9 IDE regarding your Java 9 code
are colored using yellow, and Java 9 coding errors that prevent compilation of an executable (JAR) will be
colored using red.
Line 20 also shows that NetBeans is offering to convert your Button object event handling to a Lambda
Expression by underlining it in yellow (warning: this can be converted to a Java 8 Lambda Expression).

Free download pdf