SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
JavaFX - Architecture
JavaFX is a software platform that allows developers to build various
content-rich client applications, which operate consistently across several
platforms.
It is a complete API with a rich set of classes and interfaces to build GUI
applications with rich graphics. Some of the important packages of this
API are –
 javafx.animation − Contains classes to add transition based animations such
as fill, fade, rotate, scale and translation, to the JavaFX nodes.
 javafx.application − Contains a set of classes responsible for the JavaFX
application life cycle.
 javafx.css − Contains classes to add CSSlike styling to JavaFX GUI
applications.
 javafx.event − Contains classes and interfaces to deliver and handle JavaFX
events.
 javafx.geometry − Contains classes to define 2D objects and perform
operations on them.
 javafx.stage − This package holds the top level container classes for JavaFX
application.
 javafx.scene − This package provides classes and interfaces to support the
scene graph. In addition, it also provides sub-packages such as canvas,
chart, control, effect, image, input, layout, media, paint, shape, text,
transform, web, etc. There are several components that support this rich
API of JavaFX.
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.
JavaFX - Application
As we have already learned, JavaFX is an open source free software
platform, that allows a user to develop client applications that work
consistently across various devices. Using JavaFX, one can create Graphical
User Interface applications (GUIs), and Internet or Desktop applications as
well. All these applications will be developed in Java.
JavaFX Application Structure
In general, a JavaFX application will have three major components
namely Stage, Scene and Nodes as shown in the following diagram.
Stage
A stage (a window) contains all the objects
of a JavaFX application. It is represented
by Stage class of the package javafx.stage. The
primary stage is created by the platform
itself. The created stage object is passed as
an argument to the start() method of
the Application class (explained in the next
section).
A stage has two parameters determining its
position namely Width and Height. It is
divided as Content Area and Decorations
(Title Bar and Borders).
There are five types of stages available −
 Decorated
 Undecorated
 Transparent
 Unified
 Utility
You have to call the show() method to display the contents of a stage.
Scene
A scene represents the physical contents of a JavaFX application. It contains
all the contents of a scene graph. The class Scene of the
package javafx.scene represents the scene object. At an instance, the scene
object is added to only one stage.
You can create a scene by instantiating the Scene Class. You can opt for the
size of the scene by passing its dimensions (height and width) along with
the root node to its constructor.
Scene Graph and Nodes
A scene graph is a tree-like data structure (hierarchical) representing the
contents of a scene. In contrast, a node is a visual/graphical object of a scene
graph.
A node 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.
The Node Class of the package javafx.scene represents a node in JavaFX, this
class is the super class of all the nodes.
A node is of three types −
 Root Node − The first Scene Graph is known as the Root node.
 Branch Node/Parent Node − The node with child nodes are known as
branch/parent nodes. The abstract class named Parent of the
package javafx.scene is the base class of all the parent nodes, and those parent
nodes will be of the following types −
o Group − A group node is a collective node that contains a list of children
nodes. Whenever the group node is rendered, all its child nodes are
rendered in order. Any transformation, effect state applied on the group
will be applied to all the child nodes.
o Region − It is the base class of all the JavaFX Node based UI Controls,
such as Chart, Pane and Control.
o WebView − This node manages the web engine and displays its contents.
 Leaf Node − The node without child nodes is known as the leaf node. For
example, Rectangle, Ellipse, Box, ImageView, MediaView are examples of leaf
nodes.
It is mandatory to pass the root node to the scene graph. If the Group is
passed as root, all the nodes will be clipped to the scene and any alteration
in the size of the scene will not affect the layout of the scene.
Creating a JavaFX Application
To create a JavaFX application, you need to instantiate the Application class
and implement its abstract method start(). In this method, we will write the
code for the JavaFX Application.
Application Class
The Application class of the package javafx.application is the entry point of the
application in JavaFX. To create a JavaFX application, you need to inherit this
class and implement its abstract method start(). In this method, you need to
write the entire code for the JavaFX graphics
In the main method, you have to launch the application using
the launch() method. This method internally calls the start() method of the
Application class as shown in the following program.
Within the start() method, in order to create a typical JavaFX application, you
need to follow the steps given below −
 Prepare a scene graph with the required nodes.
 Prepare a Scene with the required dimensions and add the scene graph (root
node of the scene graph) to it.
 Prepare a stage and add the scene to the stage and display the contents of the
stage.
Preparing the Scene
A JavaFX scene is represented by the Scene class of the package javafx.scene.
You can create a Scene by instantiating this class as shown in the following
code block.
While instantiating, it is mandatory to pass the root object to the constructor
of the scene class.
You can also pass two parameters of double type representing the height and
width of the scene as shown below.
Preparing the Stage
This is the container of any JavaFX application and it provides a window for
the application. It is represented by the Stage class of the package javafx.stage.
An object of this class is passed as a parameter of the start() method of
the Application class.
Using this object, you can perform various operations on the stage. Primarily
you can perform the following −
 Set the title for the stage using the method setTitle().
 Attach the scene object to the stage using the setScene() method.
 Display the contents of the scene using the show() method as shown below.
Lifecycle of JavaFX Application
The JavaFX Application class has three life cycle methods, which are −
 start() − The entry point method where the JavaFX graphics code is to be
written.
 stop() − An empty method which can be overridden, here you can write the
logic to stop the application.
 init() − An empty method which can be overridden, but you cannot create stage
or scene in this method.
In addition to these, it provides a static method named launch() to launch
JavaFX application.
Since the launch() method is static, you need to call it from a static context
(main generally). Whenever a JavaFX application is launched, the following
actions will be carried out (in the same order).
 An instance of the application class is created.
 Init() method is called.
 The start() method is called.
 The launcher waits for the application to finish and calls the stop() method.
Terminating the JavaFX Application
When the last window of the application is closed, the JavaFX application is
terminated implicitly. You can turn this behavior off by passing the Boolean
value False to the static method setImplicitExit() (should be called from a static
context).
You can terminate a JavaFX application explicitly using the
methods Platform.exit() or System.exit(int).

More Related Content

PDF
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
PDF
Demo on JavaFX
PDF
Domain Driven Design
PDF
Introduction to JavaFX
PDF
JavaFXaeurwstkiryikryiuyoyiloyuikygi.pdf
PPTX
JavaFX ALA ppt.pptx
PPTX
Java fx
PDF
Java fx
UNIT 5-JavaFX Event Handling, Controls and Components.pdf
Demo on JavaFX
Domain Driven Design
Introduction to JavaFX
JavaFXaeurwstkiryikryiuyoyiloyuikygi.pdf
JavaFX ALA ppt.pptx
Java fx
Java fx

Similar to JavaFx Introduction, Basic JavaFx Architecture (20)

PPT
Unit 1 informatica en ingles
PPT
Unit i informatica en ingles
ODP
JavaFX in Action Part I
ODP
Java Fx Overview Tech Tour
PDF
Javafx tutorial
PDF
Javafx tutorial
PDF
Javafx tutorial
PDF
The Brainify App - JavaFx
PPTX
Untitled (1)-------------------------------------------------.pptx
PPTX
Introduction to JavaFX
PDF
Programming with JavaFX
PPTX
Complete Solution for JavaFX Development - NexSoftSys
PPTX
Java AWT and Java FX
PPT
What is java fx?
PDF
JavaFX for Java Developers
PDF
JavaFX: A Rich Internet Application (RIA) Development Platform
PDF
Java FX Part2
PPTX
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
PDF
002- JavaFX Tutorial - Getting Started
PPTX
JavaFX Presentation
Unit 1 informatica en ingles
Unit i informatica en ingles
JavaFX in Action Part I
Java Fx Overview Tech Tour
Javafx tutorial
Javafx tutorial
Javafx tutorial
The Brainify App - JavaFx
Untitled (1)-------------------------------------------------.pptx
Introduction to JavaFX
Programming with JavaFX
Complete Solution for JavaFX Development - NexSoftSys
Java AWT and Java FX
What is java fx?
JavaFX for Java Developers
JavaFX: A Rich Internet Application (RIA) Development Platform
Java FX Part2
Java Core | JavaFX 2.0: Great User Interfaces in Java | Simon Ritter
002- JavaFX Tutorial - Getting Started
JavaFX Presentation
Ad

More from Jainul Musani (20)

PDF
Core Java Interface Concepts for BCA Studetns
PDF
Java Abstract and Final Class for BCA students
PDF
Java Collection Framework for BCA Students
PDF
Simple Calculator using JavaFx a part of Advance Java
PDF
ASP.NET 2010, WebServices Full Example for BCA Students
PDF
Palindrome Programme in PHP for BCA students
PDF
Leap Year Program in PHP for BCA students
PDF
"PHP and MySQL CRUD Operations for Student Management System"
PDF
Python: The Versatile Programming Language - Introduction
PPTX
Python a Versatile Programming Language - Introduction
PDF
React js t8 - inlinecss
PDF
React js t7 - forms-events
PDF
React js t6 -lifecycle
PDF
React js t5 - state
PDF
React js t4 - components
PDF
React js t3 - es6
PDF
React js t2 - jsx
PDF
React js t1 - introduction
PPTX
ExpressJs Session01
PPTX
NodeJs Session03
Core Java Interface Concepts for BCA Studetns
Java Abstract and Final Class for BCA students
Java Collection Framework for BCA Students
Simple Calculator using JavaFx a part of Advance Java
ASP.NET 2010, WebServices Full Example for BCA Students
Palindrome Programme in PHP for BCA students
Leap Year Program in PHP for BCA students
"PHP and MySQL CRUD Operations for Student Management System"
Python: The Versatile Programming Language - Introduction
Python a Versatile Programming Language - Introduction
React js t8 - inlinecss
React js t7 - forms-events
React js t6 -lifecycle
React js t5 - state
React js t4 - components
React js t3 - es6
React js t2 - jsx
React js t1 - introduction
ExpressJs Session01
NodeJs Session03
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
KodekX | Application Modernization Development
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
madgavkar20181017ppt McKinsey Presentation.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Chapter 2 Digital Image Fundamentals.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
KodekX | Application Modernization Development
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Advanced methodologies resolving dimensionality complications for autism neur...
Per capita expenditure prediction using model stacking based on satellite ima...
GamePlan Trading System Review: Professional Trader's Honest Take
MYSQL Presentation for SQL database connectivity
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf

JavaFx Introduction, Basic JavaFx Architecture

  • 1. JavaFX - Architecture JavaFX is a software platform that allows developers to build various content-rich client applications, which operate consistently across several platforms. It is a complete API with a rich set of classes and interfaces to build GUI applications with rich graphics. Some of the important packages of this API are –  javafx.animation − Contains classes to add transition based animations such as fill, fade, rotate, scale and translation, to the JavaFX nodes.  javafx.application − Contains a set of classes responsible for the JavaFX application life cycle.  javafx.css − Contains classes to add CSSlike styling to JavaFX GUI applications.  javafx.event − Contains classes and interfaces to deliver and handle JavaFX events.  javafx.geometry − Contains classes to define 2D objects and perform operations on them.  javafx.stage − This package holds the top level container classes for JavaFX application.  javafx.scene − This package provides classes and interfaces to support the scene graph. In addition, it also provides sub-packages such as canvas, chart, control, effect, image, input, layout, media, paint, shape, text, transform, web, etc. There are several components that support this rich API of JavaFX. JavaFX Architecture The following illustration shows the architecture of JavaFX API. Here you can see the components that support JavaFX API.
  • 2. 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.
  • 3. JavaFX - Application As we have already learned, JavaFX is an open source free software platform, that allows a user to develop client applications that work consistently across various devices. Using JavaFX, one can create Graphical User Interface applications (GUIs), and Internet or Desktop applications as well. All these applications will be developed in Java. JavaFX Application Structure In general, a JavaFX application will have three major components namely Stage, Scene and Nodes as shown in the following diagram. Stage A stage (a window) contains all the objects of a JavaFX application. It is represented by Stage class of the package javafx.stage. The primary stage is created by the platform itself. The created stage object is passed as an argument to the start() method of the Application class (explained in the next section). A stage has two parameters determining its position namely Width and Height. It is divided as Content Area and Decorations (Title Bar and Borders). There are five types of stages available −  Decorated  Undecorated  Transparent  Unified  Utility You have to call the show() method to display the contents of a stage. Scene A scene represents the physical contents of a JavaFX application. It contains all the contents of a scene graph. The class Scene of the package javafx.scene represents the scene object. At an instance, the scene object is added to only one stage.
  • 4. You can create a scene by instantiating the Scene Class. You can opt for the size of the scene by passing its dimensions (height and width) along with the root node to its constructor. Scene Graph and Nodes A scene graph is a tree-like data structure (hierarchical) representing the contents of a scene. In contrast, a node is a visual/graphical object of a scene graph. A node 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. The Node Class of the package javafx.scene represents a node in JavaFX, this class is the super class of all the nodes. A node is of three types −  Root Node − The first Scene Graph is known as the Root node.  Branch Node/Parent Node − The node with child nodes are known as branch/parent nodes. The abstract class named Parent of the package javafx.scene is the base class of all the parent nodes, and those parent nodes will be of the following types − o Group − A group node is a collective node that contains a list of children nodes. Whenever the group node is rendered, all its child nodes are rendered in order. Any transformation, effect state applied on the group will be applied to all the child nodes. o Region − It is the base class of all the JavaFX Node based UI Controls, such as Chart, Pane and Control. o WebView − This node manages the web engine and displays its contents.  Leaf Node − The node without child nodes is known as the leaf node. For example, Rectangle, Ellipse, Box, ImageView, MediaView are examples of leaf nodes. It is mandatory to pass the root node to the scene graph. If the Group is passed as root, all the nodes will be clipped to the scene and any alteration in the size of the scene will not affect the layout of the scene.
  • 5. Creating a JavaFX Application To create a JavaFX application, you need to instantiate the Application class and implement its abstract method start(). In this method, we will write the code for the JavaFX Application. Application Class The Application class of the package javafx.application is the entry point of the application in JavaFX. To create a JavaFX application, you need to inherit this class and implement its abstract method start(). In this method, you need to write the entire code for the JavaFX graphics In the main method, you have to launch the application using the launch() method. This method internally calls the start() method of the Application class as shown in the following program. Within the start() method, in order to create a typical JavaFX application, you need to follow the steps given below −  Prepare a scene graph with the required nodes.  Prepare a Scene with the required dimensions and add the scene graph (root node of the scene graph) to it.  Prepare a stage and add the scene to the stage and display the contents of the stage.
  • 6. Preparing the Scene A JavaFX scene is represented by the Scene class of the package javafx.scene. You can create a Scene by instantiating this class as shown in the following code block. While instantiating, it is mandatory to pass the root object to the constructor of the scene class. You can also pass two parameters of double type representing the height and width of the scene as shown below. Preparing the Stage This is the container of any JavaFX application and it provides a window for the application. It is represented by the Stage class of the package javafx.stage. An object of this class is passed as a parameter of the start() method of the Application class. Using this object, you can perform various operations on the stage. Primarily you can perform the following −  Set the title for the stage using the method setTitle().  Attach the scene object to the stage using the setScene() method.  Display the contents of the scene using the show() method as shown below.
  • 7. Lifecycle of JavaFX Application The JavaFX Application class has three life cycle methods, which are −  start() − The entry point method where the JavaFX graphics code is to be written.  stop() − An empty method which can be overridden, here you can write the logic to stop the application.  init() − An empty method which can be overridden, but you cannot create stage or scene in this method. In addition to these, it provides a static method named launch() to launch JavaFX application. Since the launch() method is static, you need to call it from a static context (main generally). Whenever a JavaFX application is launched, the following actions will be carried out (in the same order).  An instance of the application class is created.  Init() method is called.  The start() method is called.  The launcher waits for the application to finish and calls the stop() method. Terminating the JavaFX Application When the last window of the application is closed, the JavaFX application is terminated implicitly. You can turn this behavior off by passing the Boolean value False to the static method setImplicitExit() (should be called from a static context). You can terminate a JavaFX application explicitly using the methods Platform.exit() or System.exit(int).