Getting Started With JavaFX Technology Using Eclipse IDE
Running Your JavaFX Application on the Mobile Emulator
This section shows application developers how to run a JavaFX application on the Mobile Emulator by using the Eclipse IDE, which has the JavaFX plugin installed. The JavaFX Mobile Emulator is bundled with the JavaFX SDK and is currently available on the Windows platform only.
The JavaFX application programming interface (API) consists of desktop and common profiles. The desktop profile contains desktop-specific classes that cannot be run in mobile applications. When you use the common profile to build your JavaFX applications, you ensure that your applications can be run on both desktop computers and mobile devices.
In the previous section, you built a JavaFX application called FirstJavaFXApp and ran it as a desktop application by using the Desktop profile for running applications. In this section, you learn to run the same application code across a different screen by using the JavaFX Mobile Emulator.
- Start the Eclipse IDE, if not already started.
- Open the FirstJavaFXApp project that you created in the previous section, if not already opened.
- Expand the FirstJavaFXApp > src > gstutorial node in the Package Explorer window.
- Right-click the Main.fx node and choose Run As > Run Configurations.
- In the Run Configurations dialog box, click the drop-down arrow in the Profile - Target combo box and choose Mobile Profile - Run in Emulator from the list, as shown in the following figure.
Figure 1: Setting the Mobile Profile in The Run Configuration Window - Change the compile-time profile to Mobile.
- Click the Configure project compile-time profile link, which is circled in red in Figure 2 above.
- In the Properties for JavaFX System Library dialog box, select Mobile as the profile, as shown in Figure 3, and click OK.
The IDE compiles with the new profile. If there are any errors displayed, you need to ensure that the project compiles successfully with the new compile-time profile before attempting to launch the project again.
Figure 3: Setting the Compile-Time Profile - Click the Configure project compile-time profile link, which is circled in red in Figure 2 above.
- Back in the Run Configurations dialog box, click Run.
The IDE compiles the project and prepares the files necessary to run the application by using the Mobile Profile execution model. When the project is compiled successfully, an animated sphere is displayed on the screen of a mobile device in the Mobile Emulator, as shown in Figure 4.
Figure 4: JavaFX Sphere Run in Mobile EmulatorCongratulations! You've just run your first JavaFX application on the Mobile Emulator.
Notice that after you selected the Mobile Profile, a warning dialog appears, as shown in the following figure. It informs you that the project was previously compiled under the desktop profile. When you change the run profile of a project, it is advisable that you also change the project's compile-time profile to match the run profile you are trying to use. Otherwise, the project might not run as expected.
Figure 2: Warning Message After Mobile Profile Selected
See Working With JavaFX Samples for samples from which you can learn more about the JavaFX Script language and the Learning More About JavaFX page for additional resources.
We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Cindy Castillo
Technical Writer, Sun Microsystems