Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using JavaFX Mobile to Combat Device UI Fragmentation : Page 5

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.


advertisement

JavaFX Eclipse Plugin

The JavaFX Eclipse Plugin provides the Eclipse 3.4 IDE with the necessary JavaFX libraries, JavaFX perspective, and ties to the JavaFX SDK. To install the JavaFX Eclipse plugin, download the plugin .zip file and unzip the files into the Eclipse directory. Make sure that the JAVAFX_HOME variable is set to the JavaFX SDK location. You can check this by selecting Windows -> Preferences from the Eclipse menu bar. In the resulting Preferences window, explore the Java -> Build Path -> Classpath Variables settings to verify that a JavaFX_HOME variable exists and is set to the folder where the JavaFX SDK is installed (see Figure 19). If the variable is not provided or set appropriately, use the New… or Edit… buttons on the interface to set the variable appropriately.

To create a JavaFX application in Eclipse, just create a standard Java project. When the project is created, right-click on the project in the Eclipse Package Explorer view, select JavaFX from the menu, and then select the Add JavaFX Nature option (see Figure 20). This action adds the JavaFX libraries to the project and also opens the project in the plugin-provided JavaFX perspective.


Figure 19. Eclipse Compiles and Executes JavaFX Code: Eclipse uses the JavaFX SDK to compile and execute JavaFX code.
 
Figure 20. Adding the JavaFX Libraries to a Project: Add the JavaFX libraries to a project by right-clicking the project in the Eclipse Package Explorer view and selecting the JavaFX -> Add JavaFX Nature option.



The JavaFX Plugin also updates the New dialog window by offering options to create new JavaFX script files or a basic stage (see Figure 21). To get the New dialog window in Eclipse, select New - > Other … from the Eclipse File menu option on the menu bar or right-click on a JavaFX project in the Package Explorer and select New.

Somewhat like the JavaFX Palette in NetBeans, the Eclipse JavaFX Plugin offers a Snippets toolbar to drag and drop JavaFX code snippets into a JavaFX code editor (see Figure 22).


Figure 21. Creating New JavaFX Script Files: The Eclipse JavaFX Plugin adds the ability to create new JavaFX script files and a basic stage with a default scene.
 
Figure 22. Snippets View with the JavaFX Perspective: The Snippets view allows developers to drag and drop common JavaFX code components or snippets into the JavaFX scripts that are edited.

Unlike NetBeans, however, the color-coded highlighting is minimal and Eclipse doesn't support code completion, code folding, or documentation support. In fact, the Eclipse JavaFX Plugin appears to have a few bugs currently. As shown in Figure 23, the editor falsely detects an incompatible type error with integers. Thankfully, the false error detection does not prohibit testing the application. It should be noted that this bug is listed on the JavaFX Plugin issues list.

Figure 23. Eclipse False Error Detection: the Eclipse JavaFX Plugin appears to have difficulty understanding Integer types.

Like NetBeans, the Eclipse Plugin also allows the JavaFX application to be executed in one of four ways:

  • Run As Application (on the desktop)
  • Run As Applet (in a browser)
  • Run with Web Start
  • Run in Emulator

To execute a JavaFX Script, right-click on the JavaFX script file in the Package Explorer view and select Run As -> JavaFX Application (see Figure 24 and Figure 25).


Figure 24. Executing a JavaFX Script by Selecting the Profile – Target: In this first execution, the developer selects the Profile – Target.
 
Figure 25. Executing a JavaFX Script by Right-clicking on File: Right-click on the JavaFX script file in the Package Explorer view and select Run As -> JavaFX Application.

In the resulting Edit Configuration window, you can select an appropriate Profile – Target for your runtime environment. Subsequent runs of the application will use the same configuration and thus the same platform. To execute in a different mode, right click on the JavaFX script file in the Package Explorer view and select Run As -> Run Configurations… (see Figure 26). The Run Configurations window allows you to pick a different Profile-Target.

Figure 26. Changing the Runtime Environment: Select Run Configuration… to change the Profile – Target and therefore the runtime environment.

Eclipse can also be configured to indicate which profile to use when compiling and executing the JavaFX applications. Right click on a JavaFX project and select the Properties option in the resulting menu. In the Properties window, select the Java Build Path and then the Libraries tab. From this tab, you can edit the properties of the JavaFX System Library by selecting the library in the listing and pressing the Edit button (see Figure 27 and Figure 28). In the resulting Edit Library dialog window, you can select between the Desktop and Mobile profiles. When the Mobile profile is selected, elements from the Desktop profile will no longer successfully compile (or run) with your JavaFX applications. Again, this makes for a nice safety feature to ensure your JavaFX applications are truly portable.

Neither IDE supports WYSIWYG, drag-and-drop style visual development. According to many of the blogs, forums, and comments on the JavaFX tools, this is a feature soon to be added in future releases of the tools.


Figure 27. Editing the Properties of the JavaFX System Library: You can edit the properties of the JavaFX System Library by selecting the library in the listing and pressing the Edit button.
 
Figure 28. Changing the Profile Used to Compile (and Execute) JavaFX Scripts: Use the Properties window and select the Java Build Path to be able to find the JavaFX System Library.

Interestingly, the Eclipse JavaFX Plugin is made available through the Kenai Project. In addition to the Eclipse plugin, Kenai also offers a number of JavaFX applications: a few games, a few tools, and even a JavaFX Twitter client. Sun provides a number of demonstration applications on the javafx.com web site. To see some additional examples of what JavaFX can do, visit the Kenai web site.

The Wrap Up

After working with JavaFX for just a few minutes, you will see that this technology does offer hope that applications can be built, tested, and deployed to a very wide variety of platforms and UI screens all from the same source code. Can the tools, which are adequate today, eventually make developing JavaFX UIs a breeze? Will device vendors truly support the JavaFX platform? Will deploying applications to the diverse set of platforms be just as easy? None of these questions have answers today, but given the prospects, JavaFX and JavaFX Mobile certainly bear watching.



Jim White is an instructor with Intertech Training. He is also co-author of Java 2 Micro Edition, (Manning).
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap