RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using JavaFX Mobile to Combat Device UI Fragmentation : Page 3

JavaFX 1.1, a powerful tool for building rich UIs across a multitude of clients, provides mobile emulation for developing JavaFX Mobile applications. Get a beginner's guide to JavaFX Mobile development.


Working with the JavaFX SDK

The JavaFX SDK provides a set of command-line tools to compiling, running, and testing JavaFX applications. Also provided with the SDK is a mobile device emulator for running and testing JavaFX Mobile applications. In particular, if you look into the bin folder of the SDK installation, you will find javafxc.exe and javafx.exe. These two tools are the JavaFX compiler and JavaFX runtime (which operates on top of a standard JVM), respectively.

The javafxc tool works similarly to the standard javac.exe tool. The compiler takes JavaFX source code (code saved in .fx files) and compiles them to Java byte code in classes (.class files). Figure 8 shows how to compile the previously discussed Hello World JavaFX code—after it has been saved in a file called Test.fx—using javafxc.exe, and Figure 9 shows how to execute it using javafx.exe.

Figure 8. JavaFX Code Saved in Test.fx file: The example JavaFX code from Listing 1 is saved in a file called Test.fx.
Figure 9. JavaFX Code Executed Using javafx.exe: Here is how to execute the Hello World JavaFX code using javafx.exe.

Also provided in the bin directory are JavaFX packaging and documentation tools. The packaging tool (javafxpackager.exe) is of particular interest to mobile developers because it provides the means to create a mobile-ready package for deployment to a mobile device or emulator. However, the packaging tool can also be used to create browser-ready or Web Start applications from JavaFX code.

To create the Java Application Descriptor (JAD) and JAR files for mobile device/emulator deployment, you must at least provide the javafxpackager tool with the location of the .fx file source code (it does not have to be compiled to .class files first) and the name of the main class or starting point class for the application.

By default, the javafxpackager creates a set of deployment files for browser or Web Start deployment. To create the JAD and JAR files for mobile deployment, you must also use the –p mobile option in the command line request. The –p is for "profile" and you can indicate mobile or desktop options with this switch.

Here is the full javafxpackager command to create a mobile-ready application from the Test.fx file (located in the c:\jfx folder for this example):

javafxpackager -src c:\jfx -appClass Test -p mobile -d c:\jfx\dist

The –src option specifies the source of the JavaFX script code, -appClass specifies the name of the main class, and the optional –d option specifies destination of the output (the .JAD and .JAR files). See Figure 10 for the results.

Again, without the –p mobile option (or by specifying –p desktop), the javafxpackager produces HTML, JAR, and JNLP files suitable for browser or Web Start execution as shown in Figure 11.

Also shipped with the Windows version of the JavaFX SDK is an emulator to test the applications. You should find an emulator.exe located in the /emulator/bin subfolder of the JavaFX SDK install directory. To test the JavaFX JAD/JAR files produced by the javafxpackager, call on the emulator tool with the JAD file. Use the –Xdescriptor: option to specify the JAD file to execute as shown in Figure 12.

Figure 10. Using the javafxpackger.exe with a –p mobile Option: Using the javafxpackger.exe with a –p mobile option creates a JAD and a JAR file.
Figure 11. Use the javafxpackger.exe Without a –p mobile Option: Use the javafxpackger.exe without a –p mobile option or with a –p desktop option to create all the files for browser or Web Start execution.
Figure 12. Test a JavaFX Application on the JavaFX SDK's Emulator: Find the emulator executable in the /emulator/bin directory of the JavaFX SDK.

In addition to the tools and emulator, the JavaFX SDK comes with sample applications, documentation, and of course the JavaFX libraries and API.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date