Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

JavaFX Architecture

The document outlines the architecture of JavaFX, detailing its components such as Scene Graph, Prism, GWT, Quantum Toolkit, WebView, and Media Engine, which facilitate the development of GUI applications. It explains the structure of the Scene Graph, the rendering capabilities of Prism, and the functionalities of WebView and the Media Engine for handling web content and media playback. Additionally, a Java program example is provided to demonstrate reading from one file and writing to another, highlighting exception handling during file operations.

Uploaded by

smonishacpt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

JavaFX Architecture

The document outlines the architecture of JavaFX, detailing its components such as Scene Graph, Prism, GWT, Quantum Toolkit, WebView, and Media Engine, which facilitate the development of GUI applications. It explains the structure of the Scene Graph, the rendering capabilities of Prism, and the functionalities of WebView and the Media Engine for handling web content and media playback. Additionally, a Java program example is provided to demonstrate reading from one file and writing to another, highlighting exception handling during file operations.

Uploaded by

smonishacpt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

JavaFX Architecture

The following illustration shows the architecture of JavaFX API. Here you can see the components
that support JavaFX API.

Scene Graph

In JavaFX, the GUI Applications were coded using a Scene Graph. A Scene Graph is the starting point
of the construction of the GUI Application. It holds the (GUI) application primitives that are termed
as nodes.

A node is a visual/graphical object and it may include −

 Geometrical (Graphical) objects − (2D and 3D) such as circle, rectangle, polygon, etc.

 UI controls − such as Button, Checkbox, Choice box, Text Area, etc.

 Containers − (layout panes) such as Border Pane, Grid Pane, Flow Pane, etc.

 Media elements − such as audio, video and image objects.

In general, a collection of nodes makes a scene graph. All these nodes are arranged in a hierarchical
order as shown below.
Each node in the scene graph has a single parent, and the node which does not contain any parents
is known as the root node.

In the same way, every node has one or more children, and the node without children is termed
as leaf node; a node with children is termed as a branch node.

A node instance can be added to a scene graph only once. The nodes of a scene graph can have
Effects, Opacity, Transforms, Event Handlers, Event Handlers, Application Specific States.

Prism

Prism is a high performance hardware–accelerated graphical pipeline that is used to render the
graphics in JavaFX. It can render both 2-D and 3-D graphics.

To render graphics, a Prism uses −

 DirectX 9 on Windows XP and Vista.

 DirectX 11 on Windows 7.

 OpenGL on Mac and Linux, Embedded Systems.

In case the hardware support for graphics on the system is not sufficient, then Prism uses the
software render path to process the graphics.

When used with a supported Graphic Card or GPU, it offers smoother graphics. Just in case the
system does not support a graphic card, then Prism defaults to the software rendering stack (either
of the above two).

GWT (Glass Windowing Toolkit)

As the name suggests, GWT provides services to manage Windows, Timers, Surfaces and Event
Queues. GWT connects the JavaFX Platform to the Native Operating System.

Quantum Toolkit
It is an abstraction over the low-level components of Prism, Glass, Media Engine, and Web Engine. It
ties Prism and GWT together and makes them available to JavaFX.

WebView

Using JavaFX, you can also embed HTML content in to a scene graph. WebView is the component of
JavaFX which is used to process this content. It uses a technology called Web Kit, which is an internal
open-source web browser engine. This component supports different web technologies like HTML5,
CSS, JavaScript, DOM and SVG.

Using WebView, you can −

 Render HTML content from local or remote URL.

 Support history and provide Back and Forward navigation.

 Reload the content.

 Apply effects to the web component.

 Edit the HTML content.

 Execute JavaScript commands.

 Handle events.

In general, using WebView, you can control web content from Java.

Media Engine

The JavaFX media engine is based on an open-source engine known as a Streamer. This media
engine supports the playback of video and audio content.

The JavaFX media engine provides support for audio for the following file formats −

 MP3

Audio  WAV

 AIFF

Video  FLV

The package javafx.scene.media contains the classes and interfaces to provide media functionality in
JavaFX. It is provided in the form of three components, which are −

 Media Object − This represents a media file

 Media Player − To play media content.

 Media View − To display media.


2. Write a java program to read data from a file and to write data to file

// Java program to read content from one file

// and write it into another file

// Custom paths for this program

// Reading from - gfgInput.txt

// Writing to - gfgOutput.txt

// Importing input output classes

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

// Class

class GFG {

// Main driver method

public static void main(String[] args)

// The file reading process may sometimes give

// IOException

// Try block to check for exceptions

try {

// Creating a FileReader object and

// file to be read is passed as in parameters

// from the local directory of computer

FileReader fr = new FileReader("gfgInput.txt");


// FileReader will open that file from that

// directory, if there is no file found it will

// through an IOException

// Creating a FileWriter object

FileWriter fw = new FileWriter("gfgOutput.txt");

// It will create a new file with name

// "gfgOutput.text", if it is already available,

// then it will open that instead

// Declaring a blank string in which

// whole content of file is to be stored

String str = "";

int i;

// read() method will read the file character by

// character and print it until it end the end

// of the file

// Condition check

// Reading the file using read() method which

// returns -1 at EOF while reading

while ((i = fr.read()) != -1) {

// Storing every character in the string

str += (char)i;

// Print and display the string that


// contains file data

System.out.println(str);

// Writing above string data to

// FileWriter object

fw.write(str);

// Closing the file using close() method

// of Reader class which closes the stream &

// release resources that were busy in stream

fr.close();

fw.close();

// Display message

System.out.println(

"File reading and writing both done");

// Catch block to handle the exception

catch (IOException e) {

// If there is no file in specified path or

// any other error occurred during runtime

// then it will print IOException

// Display message

System.out.println(

"There are some IOException");

You might also like