Surveying JavaFX Features (Getting a Jump Start in JavaFX)

We close this topic by surveying many of the features of JavaFX, some of which are a review for you. We do this by describing several of the more commonly used packages and classes in the JavaFX SDK API.

The javafx.stage package contains:

• The Stage class, which is the top level of the UI containment hierarchy for any JavaFX application, regardless of where it is deployed (such as the desktop, a browser, or a cell phone).

• The Screen class, which represents the displays on the machine in which a JavaFX program is running. This enables you to get information about the screens, such as size and resolution.

The javafx.scene package contains some classes that you’ll use often:

• The Scene class is the second level of the UI containment hierarchy for JavaFX applications. It includes all of the UI elements contained in the application. These elements are called graphical nodes, or simply nodes.

• The Node class is the base class of all of the graphical nodes in JavaFX, UI elements such as text, images, media, shapes, and controls (such as text boxes and buttons) are all subclasses of Node. Take a moment to look at the variables and functions in the Node class to appreciate the capabilities provided to all of its subclasses, including bounds calculation and mouse and keyboard event handling.

• The Group class is a subclass of the Node class whose purpose includes grouping nodes together into a single co-ordinate space and allowing transforms (such as rotate) to be applied to the whole group. Also, attributes of the group that are changed (such as opacity) apply to all of the nodes contained within the group.


Several packages begin with javafx.scene that contain subclasses of Node of various types.

For example:

• The javafx.scene.image package contains the Image and ImageView classes, which enable images to be displayed in the Scene. The ImageView class is a subclass of Node.

• The javafx.scene.shape package contains several classes for drawing shapes such as Circle, Rectangle, Line, Polygon, and Arc. The base class of the shapes, named Shape, contains an attribute named fill that enables you to specify a color or gradient with which to fill the shape.

• The javafx.scene.text package contains the Text class for drawing text in the scene. The Font class enables you to specify the font name and size of the text.

• The javafx.scene.media package has classes that enable you to play media. The MediaView class is a subclass of Node that displays the media.

• The javafx.scene.chart package has classes that help you easily create area, bar, bubble, line, pie, and scatter charts. The corresponding UI classes in this package are AreaChart, BarChart, BubbleChart, LineChart, PieChart, and ScatterChart.

Here are some other packages in the JavaFX 1.2 API.

• The javafx.scene.control package contains several UI controls, each one having the ability to be skinned and styled via CSS.

• The javafx.scene.transform package enables you to transform nodes (scale, rotate, translate, shear, and affine).

• The javafx.scene.input package contains classes such as MouseEvent and KeyEvent that provide information about these events from within an event handler function such as the Node class’s onMouseClicked event.

• The javafx.scene.layout package contains several layout containers, including HBox, VBox, BorderPane, FlowPane, StackPane, and TilePane.

• The javafx.scene.effect and javafx.scene.effect.light packages contain easy-to-use effects such as Reflection, Glow, Shadow, BoxBlur, and Lighting.

• The javafx.scene.web package contains classes for easily embedding a web browser in your JavaFX applications.

• The javafx.animation package contains time-based interpolations typically used for animation, and convenience classes for common transitions, respectively.

• The javafx.beans, javafx.beans.binding, javafx.beans.property, and javafx.beans.value packages contain classes that implement properties and binding.

• The javafx.fxml package contains classes that implement a very powerful facility known as FXML,a markup language for expressing JavaFX user interfaces in XML.

• The javafx.builder package contains builder classes such as the ones demonstrated in earlier in this topic.

• The javafx.util package contains utility classes such as the Duration class used in the HelloEarthRise example earlier in this topic.

Take a look at the JavaFX API docs again in light of the information to get a deeper sense of how you can use its capabilities.

Summary

Congratulations, you learned a lot about JavaFX in this topic, including:

• JavaFX is rich-client Java, and is needed by the software development industry.

• Java SE 6 Update 10 is a technology by Sun that solves the deployment problems that have prevented the Java Runtime Environment (JRE) from being ubiquitous on client machines. Java SE 6 Update 10 also addresses the ease and speed of deploying Java/JavaFX applications.

• Some of the high points of the history of JavaFX.

• Where to find JavaFX resources, including the JavaFX SDK, the JavaFX plug-in for NetBeans, and the API documentation.

• How to compile and run a JavaFX program from the command-line.

• How to declaratively express a user interface in JavaFX, using builder classes.

• How to build and run a JavaFX program using NetBeans.

• How to use several of the classes in the JavaFX API.

• How to create a class in JavaFX and use it as a model contains the state of a JavaFX application.

• How to use property binding to keep the UI easily in sync with the model.

We also looked at many of the available API packages and classes, and you learned how you can leverage their capabilities. Now that you have a jump start in JavaFX.

Resources

For some background information on JavaFX, you can consult the following resources.

• Java Posse #163: Newscast for February 8,2008: This is a podcast of a Java Posse interview with Josh Marinacci and Richard Bair on the subject of JavaFX. The URL is www.javaposse.com/index.php?post_id=305735.

• "Mind-Bendingly Cool Innovation": This article contains an interview with Chris Oliver, the founder of JavaFX The URL is http://research.sun.com/minds/2008-1202/.

• "Development and Deployment of Java Web Apps (Applets and Java Web Start Applications) for JavaSE 6u10": This set of web pages from Sun discusses the features of Java SE 6 Update 10 and how to use them. The URL is http://java.sun.eom/javase/6/docs/technotes/guides/jweb/index.htmL

• Oracles’s JavaFX.com site: The home page for JavaFX where you can download the JavaFX SDK and other resource for JavaFX. The URL is http://www.javafx.com.

• FX Experience: A blog maintained by Oracle JavaFX Engineers Richard Bair, Jasper Potts, and Jonathan Giles. The URL is http://fxexperience.com.

  • JavaFX Eclipse Plugin: Eclipse tooling for JavaFX 2.0, being developed by Tom Shindl. The URL for the announcement is http://tomsondev.bestsolution .at/2011/06/24/introducing-efxclipse/.

• JavaFX 2.0 Roadmap: The roadmap and associated milestones published by Oracle for JavaFX 2.0.

Next post:

Previous post: