Java Reference
In-Depth Information
any JavaFX application, as it provides a great starting point for building more sophist-
icated solutions.
To create a simple JavaFX Hello World application using your favorite text editor,
follow Solution 2, Steps 1 and 2. To compile and run your Hello World program on the
command line, follow Solution 2, Steps 3 and 4. Once you enter the source code into
your favorite editor and save the source file, compile and run the JavaFX program.
Open the command-line or terminal window and navigate to the directory location of
the Java file named HelloWorldMain.java .
Here, we review a way to compile the file using the command javac -d .
HelloWorldMain.java . You will notice the -d . before the file name. This lets
the Java compiler know where to put class files based on their package name. In this
scenario, the HelloWorldMain package statement is helloworldmain , which
will create a subdirectory under the current directory. The following commands will
compile and run the JavaFX Hello World application:
cd \<path to
project>\org\java8recipes\chapter14\recipe14_01
javac -d . HelloWorldMain.java
java helloworldmain.HelloWorldMain
Note There are many ways to package and deploy JavaFX applications. To learn
more, see “Learning How to Deploy and Package JavaFX Applications” at ht-
tp://docs.oracle.com/javafx/2/deployment/jfxpub-deploy-
ment.htm . For in-depth JavaFX deployment strategies, see Oracle's “Deploying
JavaFX Applications” at http://docs.oracle.com/javafx/2/deploy-
ment/deployment_toolkit.htm .
In both solutions you'll notice in the source code that JavaFX applications extend
the javafx.application.Application class. The Application class
provides application lifecycle functions such as launching and stopping during runtime.
This also provides a mechanism for Java applications to launch JavaFX GUI compon-
ents in a threadsafe manner. Keep in mind that synonymous to Java Swing's event dis-
patch thread, JavaFX has its own JavaFX application thread. New in JavaFX 8, it is
possible for the event dispatch thread and the JavaFX application thread to be merged
(see Recipe 14-18).
Search WWH ::




Custom Search