What is JavaFX
The JavaFX platform is a rich client platform solution that makes it easy to create cross-platform rich client applications with application developers. Built on Java technology, the JavaFX platform provides a rich set of graphics and media APIs and a high-performance hardware-accelerated graphics and media engine that simplifies the development of data-driven enterprise client applications.
JavaFX has the following advantages:
- Because the JavaFX platform is written in Java, Java developers can leverage existing skills and tools to develop JAVAFX applications.
- Because Java is widely used, it is easy to find developers who can easily turn JavaFX applications into products.
- Because the same server and client platforms are used with Java technology, the risks associated with applying enterprise solutions are reduced.
- As a result of the above advantages, development costs will also be reduced.
- JavaFX provides developers with a development framework and a running environment for creating cross-platform, enterprise-class business applications.
The architecture and framework of JavaFX
The JavaFX platform is a cross-platform application built on Java technology and easy to create and deploy rich client platforms.
Describes the overall architecture of JavaFX 2, describing how the individual parts and parts are linked together. You can run your JavaFX code on the basis of the JavaFX API below. It includes JavaFX's high-performance graphics engine called prism; a small and efficient window system called glass; there is also a media engine and a Web engine. Although these components are not public, their descriptions can help you better understand how to run a JavaFX application.
Figure 1. JavaFx 2 Overall architecture
Scene map
JavaFX's scene map, shown at the top of the overall frame, is the starting point for the overall JavaFX application. It is a hierarchical tree-like node that represents the visual elements of the application user interface. It can process input and render output.
A single element in a scene is called a node. Each node has an ID, a style class, and a boundary value. Each node has a parent node and 0 to multiple child nodes, in addition to the root node. It can also have the following properties:
- Effects, such as Blur and shadows
- Transparency
- Transform parameters
- Event handling (for example: mouse, keyboard, and input)
- Specific Application Status
Unlike swing and AWT, JavaFX scene maps include layouts, images, and media, as well as rectangles and text.
In most applications, there are many easy-to-use components in the scene graph that are used.
javafx.scene
The API describes many types of components, such as:
- Nodes: Includes shapes (2-d and, images, media, embedded web browser, text, UI controls, charts, groups, and containers
- State:transforms (positioning and orientation of nodes), visual effects, and other visual state of the content
- Effects:simple objects that change the appearance of scene graph nodes, such as blurs, shadows, and color adjustment
Java APIs for JavaFX Features
JavaFX 2 has a full set of public APIs displayed at the top level. These APIs give you the flexibility to create RIA apps. The JavaFX platform combines the best functionality and integration of the Java platform, and immersive media capabilities translate into an intuitive and comprehensive one-stop development environment. These new Java API features include:
- Enables the use of powerful Java features such as generics, annotations, multithreading, and so on.
- Easy for Web developers to use JavaFX from other popular dynamic languages such as Jruby,groovy and JavaScript.
- Allows Java developers to use other system languages, such as groovy, for writing large or complex javafx applications.
- The use of bindings is similar to the JavaFX scripting language. This includes support for high-performance lazy bindings, binding expressions, binding sequence expressions, and local bindings. The selected language (such as groovy) can use this binding library to introduce binding syntax similar to JavaFX scripting.
- Extend the Java Collections Library to include lists and maps, and display them in a timely manner on the interface based on changes in the contents of the collection to monitor changes in their objects.
JavaFX 2 is backwards compatible with JavaFX 1.x. Most APIs are compatible, and some APIs, such as layout and media, also have significant improvements. JavaFX 2 supports more web standards, such as CSS styles. More standards will be supported later on.
Graphics system
The graphics system for JavaFX 2 is the blue part of Figure 1 and is the implementation of the JavaFX scenario map. It includes 2-d as well as the-box scene. It provides software optimizations for hardware rendering.
Graphical acceleration implementations of the JavaFX 2 platform:
- Prism: Process rendering work. It is capable of running hardware and software rendering including. Ability to render JavaFX scenes. There are multiple paths used for the use of the community:
DirectX 9 on Windows XP and Windows Vista
DirectX 11 on Windows 7
OpenGL in Mac, Linux, embedded
JAVA2D hardware acceleration is not possible.
When fully hardware-accelerated paths are used, it is possible, but when it is not valid, use the JAVA2D render path, because the java2d render path is already distributed across all Java runtime Environments (JRE). This is particularly important when dealing with the 3 D scenario. However, the performance of a better hardware rendering path is used.
- Quantum Toolkit: Binds prism and Windows tools so that they can be used with JavaFX. It is also responsible for thread-related rules and event handling.
Glass Windowing Toolkit
Glass Windowing Toolkit in the middle part of Figure 1, its main function is to provide local operation services, such as: Management window, timer and appearance. It provides services for connecting JAVAFX platforms and local operating systems.
The Glass Toolkit is also capable of handling event queues. Unlike AWT, it not only manages its own event queues but also manages events on the local operating system. And unlike AWT, Glass Toolkit runs a JavaFX thread and AWT runs a thread, and Java runs a thread. Many problems have been solved in this way.
Threads
The following threads are run after the system starts, including:
- JavaFX Application Thread: This is the main thread of the JavaFX application.
- Prism render Thread: This thread is processed separately through the respective event distribution program. Used for rendering event distribution.
- Media Thread: This program runs in the background using the JavaFX application thread through the last frame.
Pulse
A pulse is an event that indicates the state of the scene graph over time. A pulse normally runs at 60 frames per second. Even the animation of the scene does not change pulse can also change. For example: when the position of a button changes, then pulse will be changed.
When a pulse is triggered, the corresponding change is also synchronized with the render layer. Pulse enables application developers to handle asynchronous events. This important property allows the system to batch execute events on pulse.
Layout and CSS also have a pulse event. Many changes on the scene map will result in layout and CSS changes. The system will automatically optimize performance through pulse. The app developer can trigger the layout manually, as needed.
The Glass Windowing Toolkit is applied to perform the pulse event.
Media and Images
The media capabilities of JavaFX can be javafx.scene.media
used effectively. Provide the processing of documents such as MP3, AIFF, FLV, etc. JavaFX Media provides 3 components: Media objects as a media file, media players playing a media file, using MediaView as a node to display media files.
The media engine component, shown in the green section of Figure 1, was redesigned in JavaFX 2 and improved performance for related extensions.
Embedded Browser
JavaFX's built-in browser is a new user interface for JavaFX, which can provide full web browsing through this API. This section is shown in the orange section of Figure 1, which is based on WebKit, an open source browser engine that can provide support for HTML5, CSS, JavaScript, DOM, and SVG. It can develop the following features in Java applications:
- Render HTML content from a local or remote URL
- Supports historical browsing and provides fallback and forward navigation
- Reload Content
- Application Effects of Web Components
- Edit HTML content
- Execute JavaScript command
- Handling Events
The content browser consists of the following classes:
- The Web engine provides basic web browsing capabilities.
- A web engine WebView encapsulates an object, contains HTML content into an application's scene, and provides fields and methods for applying effects and transformations. This is the class for an extension node.
Css
JavaFX Cascading Style Sheets (CSS) provides a JAVAFX application that customizes the user interface of the style application without changing the source code of any application. CSS can be applied to any node in the JavaFX scene map and to nodes that are applied to async. JavaFX's CSS styles can also be easily assigned to scenes at run time, allowing the application's appearance to change dynamically.
There are two examples that have two different styles applied, but the components are the same.
Figure 2
JavaFX CSS is based on the CSS version 2.1 specification, and can support some CSS 3 features. JavaFX's CSS support and extensions have been designed to allow JavaFX's CSS stylesheets to be parsed cleanly through any compatible CSS parser, even without supporting JavaFX extensions. This makes the blended CSS style a single stylesheet for JavaFX and other uses (such as HTML pages). All JavaFX attribute names are prefixed with the "FX-" of the vendor extension, including those that may appear to conform to the standard HTML, because some JavaFX values have slightly different semantics.
UI Controls
They can take full advantage of the rich visual features of the JavaFX platform that can be used on different platforms. JavaFX CSS allows themes and skins for UI controls.
Figure 3 lists a subset of the components that can be used, both of which are javafx.scene.control
under.
Figure 3
Layout
Similar to other common layouts.
Deployment
There are three ways to deploy JavaFX:
Run separately: You can install the local double-click to run. In this way, the user can not access the line way.
Browser: In this way, JavaFX is embedded in a Web page that automatically loads, and it interacts with the elements on the page through JavaScript on the page.
Web launch: This method needs to be downloaded first, and once the download is complete, the user can start the application by downloading the JNLP file.
Key Features
The main features include the following:
- Fully integrated JDK7.
- Provides similar syntax attributes to the Java API.
- The new image processing engine.
- FXML, an XML-based language to define JAVAFX applications.
- A new media engine that supports Web pages that play multimedia content.
- The expansion of Web capabilities.
- A variety of built-in UI controls, including charts, tables, menus, and panes.
- Very easy to pack through the several ways described above.
- Cross-platform.
- The same API format as the Java API.
How to create a JavaFX app
- Download the latest version of the JDK and support JavaFX.
- Install and configure, follow the wizard to create a simple app.
- Download JavaFX Scene Builder and compile and run.
Using JavaFX Scene Builder
Download JavaFX Scene Builder.
Attention:
The JavaFX scene Builder is not dependent on any particular IDE. You can run it as a standalone tool to create your UI layout and edit the results fxml file using a text editor for your selection. If you choose to use the NetBeans IDE outside of this tutorial, there are sections in this tutorial that highlight what you need to do to connect the layout, you build the Java source code for the sample application, apply the stylesheet, and run the sample application using the Apache Ant utility.
The user interface of JavaFX Scene Builder.
Figure 4
Download sample Files Issuetrackinglite.zip
You can choose to open with NetBeans or by using Scene Builder.
We chose to import from NetBeans.
Figure 5
Because there is no design interface in NetBeans, the design of the interface is given to JavaFX Scene Builder, and we can run the app to get the following effect.
What is JavaFX