SlideShare a Scribd company logo
1
JavaFX in Action
Part I
Hossein Rimaz
K.N. Toosi University of Technology
2
Table of Contents
• Why JavaFX and Use Cases
• JavaFX App Architecture
• Hello World
• JavaFX Shapes
• Recursive Graphic
• Quick Introduction to Java 8 Lambda
• Event-Driven Programming
• Design Patterns and Observer
• Properties & Bindings
• Simple Graph Editor
3
Why JavaFX and Use Cases
4
History of JavaFX Using Google Trends
JavaFX Script
1.0
JavaFX
2.0
JavaFX
8
5
Where can you use JavaFX?
Basically everywhere!
● Desktop Applications
● Mobile (with Gluon Mobile)
● Web Application (require plug-ins but JPro doesn’t need any!)
● Embedded System (even ARM)
6
JavaFX App Architecture
7
JavaFX Application Life cycle
Each JavaFX application needs to extend the javafx.application.Application
class, which defines the life cycle of an application.
• Application.init() can be used to define and prepare everything before the
application starts.
• Application.start(Stage stage) is called to start the application. This
method should be used to define the complete application and its view by
adding a scene that defines the main window of the application.
• Application.stop() is called once the application is closed.
8
Structure of a JavaFX Application
9
Strange Names?
Not at all!
Think about it as a theater stage!
You have a stage; actors (Nodes) come into the scene
and going out of it.
And well this is a play, scene goes in and goes out!
Just as simple as it is!
10
Hello World
11
Creating a JavaFX Application
12
13
14
Final Result
That was a simple hello world that probably you have no idea about
it!
But the result is actually pretty!
15
JavaFX Shapes
16
JavaFX Shapes
Well, let’s start a little bit simpler.
● Let’s just draw lines!
17
Be careful about what
package you are importing!
18
JavaFX Shapes
How about adding some loops?
19
Final Result
20
More Shapes
21
Recursive Graphics
22
Recursive Graphics
● You learned recursive programming and now you can apply those
techniques to achieve stunning visual arts!
23
Drawing a Tree
Source code at: https://github.com/mhrimaz/RecursiveTreeFX
24
Sierpinski Carpet
Source code at : https://github.com/mhrimaz/SierpinskiCarpetFX
25
Quick Introduction to Java 8 Lambda
26
Java 8 New Features
● Lambda expressions
● Method references
● Default Methods (Defender methods)
● A new Stream API.
● Optional
● A new Date/Time API.
● Nashorn, the new JavaScript engine
● Removal of the Permanent Generation
● and more…
27
Lambda Expression
● A primary goal of lambdas is to help address the lack in the Java
language of a good way to express functional programming concepts.
28
Syntax
● There are two ways to specify lambda expressions. The following
simple examples illustrate the general forms:
(param1, param2, ...) -> expression;
(param1, param2, ...) -> { /* code statements */ };
● Another thing to note is that parameters can be optionally typed. The
compiler will infer the type of the parameters depending on the
context.
29
Why Lambda?
● In event handling lambda expressions will makes our codes shorter
and more expressive.
● Now you can understand NetBeans starter code better.
30
Event-Driven Programming
31
What is Event-Driven Programming?
● Until now, you may only wrote your programs in imperative way.
Your code flow was deterministic and run line after another.
● Event-driven programming is a programming paradigm in which the
flow of the program is determined by events such as user actions
(mouse clicks, key presses), sensor outputs, or messages from other
programs/threads.
● Event-driven programming is the dominant paradigm used in
graphical user interfaces and other applications that are centered on
performing certain actions in response to user input.
32
Simple Example
● Simple scenario: mouse goes in,
performs a double click and goes out.
33
Design Patterns and Observer
34
What is Design Pattern?
● In software engineering, a design pattern is a general repeatable
solution to a commonly occurring problem in software design.
A design pattern isn't a finished design that can be transformed
directly into code. It is a description or template for how to solve a
problem that can be used in many different situations.
● Design patterns can speed up the development process by providing
tested, proven development paradigms.
● In addition, patterns allow developers to communicate using well-
known, well understood names for software interactions.
35
GoF 23 Design Patterns
Creational
patterns
– Abstract Factory
– Builder
– Factory Method
– Prototype
– Singleton
Structural patterns
– Adapter
– Bridge
– Composite
– Decorator
– Façade
– Flyweight
– Proxy
Behavioral patterns
– Chain of responsibility
– Command
– Interpreter
– Iterator
– Mediator
– Memento
– Observer
– State
– Strategy
– Template method
– Visitor
36
Design Pattern and JavaFX
● Well you’ve used many of them in your development without
knowing their names.
● Knowing about observer design pattern
can help you to understand
JavaFX Properties & Bindings and It’s
Observable collections better.
● If you want to learn more
Please read this book:
Java Design Patterns by Vaskaran Sarcar
37
Observer Design Pattern
● GoF Definition: Define a one-to-many dependency between
objects so that when one object changes state, all its dependents are
notified and updated automatically.
● Concept: In this pattern, there are many observers (objects) which
are observing a particular subject (object). Observers are basically
interested and want to be notified when there is a change made inside
that subject. So, they register themselves to that subject. When they
lose interest in the subject they simply unregister from the subject.
Sometimes this model is also referred to as the Publisher-Subscriber
model.
38
Computer World Example
● In the world of computer science, consider a simple UI-based
example, where this UI is connected with some database (or business
logic).
A user can execute some query through that UI and after searching the
database, the result is reflected back in the UI. In most of the cases we
segregate the UI with the database.
If a change occurs in the database, the UI should be notified so that it
can update its display according to the change.
39
UI Patterns
● Graphical user interfaces have become a familiar part of our software
landscape, both as users and as developers. Looking at it from a
design perspective they represent a particular set of problems in
system design - problems that have led to a number of different but
similar solutions.
● When developing GUI applications you will inevitably encounter UI
architectural framework concepts such as model view controller
(MVC), model view presenter (MVP), or model view view-model
(MVVM).
40
Properties & Bindings
41
Properties & Bindings
● Properties are basically wrapper objects for JavaFX-based object
attributes such as String or Integer. Properties allow developers to add
listener code to respond when the wrapped value of an object has
changed or is flagged as invalid. Also, property objects can be bound
to one another.
● Binding behavior allows properties to update or synchronize their
values based on a changed value from another property.
42
Types of JavaFX Properties
● Read/Writable
● Read-Only
● JavaFX’s properties are wrapper objects holding actual values while providing
change support, invalidation support, and binding capabilities.
● Some Property Classes:
– javafx.beans.property.SimpleIntegerProperty
– javafx.beans.property.ReadOnlyIntegerWrapper
– javafx.beans.property.SimpleDoubleProperty
– javafx.beans.property.ReadOnlyDoubleWrapper
– javafx.beans.property.SimpleStringProperty
– javafx.beans.property.ReadOnlyStringWrapper
43
Example
Output:
StringProperty Value = password1
observable = StringProperty [value: 1234]
oldValue = password1
newValue = 1234
44
Bindings
● binding has the idea of at least two values (properties) being
synchronized. This means that when a dependent variable changes, the
other variable changes.
● JavaFX provides many binding options that enable the developer to
synchronize between properties in domain objects and GUI controls.
45
Types of JavaFX Bindings
● Simple Binding
● Bidirectional Binding
46
Example
● Binding String length to a Integer Property
47
Simple Graph Editor
Source code at: https://github.com/mhrimaz/JavaFXWorkshop_01

More Related Content

What's hot

Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance JavaVikas Goyal
 
LUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi HackingLUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi Hacking
Stephen Chin
 
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino DesignerAd103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
ddrschiw
 
Java 1
Java 1Java 1
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
Devang Garach
 
Spring ppt
Spring pptSpring ppt
Spring ppt
Mumbai Academisc
 
J2EE Struts with Hibernate Framework
J2EE Struts with Hibernate FrameworkJ2EE Struts with Hibernate Framework
J2EE Struts with Hibernate Framework
mparth
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
Why java is important in programming language?
Why java is important in programming language?Why java is important in programming language?
Why java is important in programming language?
NexSoftsys
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET Comparison
Haim Michael
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoa
Yi-Shou Chen
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
Mohit Belwal
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overviewJong Soon Bok
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 

What's hot (19)

Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
 
LUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi HackingLUGOD Raspberry Pi Hacking
LUGOD Raspberry Pi Hacking
 
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino DesignerAd103 - Have it Your Way: Extending IBM Lotus Domino Designer
Ad103 - Have it Your Way: Extending IBM Lotus Domino Designer
 
Java 1
Java 1Java 1
Java 1
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
J2EE Struts with Hibernate Framework
J2EE Struts with Hibernate FrameworkJ2EE Struts with Hibernate Framework
J2EE Struts with Hibernate Framework
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Why java is important in programming language?
Why java is important in programming language?Why java is important in programming language?
Why java is important in programming language?
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET Comparison
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
MV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoaMV(C, mvvm) in iOS and ReactiveCocoa
MV(C, mvvm) in iOS and ReactiveCocoa
 
Ch2
Ch2Ch2
Ch2
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 

Similar to JavaFX in Action Part I

MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
Ulrich Krause
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
Ulrich Krause
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
Jiby John
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
Hitesh-Java
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
PawanMM
 
Software Engineering 2014
Software Engineering 2014Software Engineering 2014
Software Engineering 2014
Shuichi Kurabayashi
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
DivyanshGupta922023
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
cNguyn506241
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
Qamar Abbas
 
Persentation
PersentationPersentation
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
Abhishek Yadav
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
Abhishek Sur
 
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
Himanshu Dudhat
 
MVC
MVCMVC
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
DevDay.org
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
DotNetMarche
 
Javascript frameworks
Javascript frameworksJavascript frameworks
Javascript frameworks
RajkumarJangid7
 
Node.js vs. java
Node.js vs. javaNode.js vs. java
Node.js vs. java
MoonTechnolabsPvtLtd
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
Mike Melusky
 

Similar to JavaFX in Action Part I (20)

MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Software Engineering 2014
Software Engineering 2014Software Engineering 2014
Software Engineering 2014
 
jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Persentation
PersentationPersentation
Persentation
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
MVP Clean Architecture
MVP Clean  Architecture MVP Clean  Architecture
MVP Clean Architecture
 
MVC
MVCMVC
MVC
 
Libreplan architecture
Libreplan architectureLibreplan architecture
Libreplan architecture
 
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
[DevDay2018] Liferay DXP – A powerful Enterprise Solution - By Vy Bui, Develo...
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
 
Javascript frameworks
Javascript frameworksJavascript frameworks
Javascript frameworks
 
Node.js vs. java
Node.js vs. javaNode.js vs. java
Node.js vs. java
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
 

More from Mohammad Hossein Rimaz

004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling
Mohammad Hossein Rimaz
 
003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
Mohammad Hossein Rimaz
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
Mohammad Hossein Rimaz
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
Mohammad Hossein Rimaz
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Mohammad Hossein Rimaz
 

More from Mohammad Hossein Rimaz (6)

004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling
 
003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 

Recently uploaded

From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

JavaFX in Action Part I

  • 1. 1 JavaFX in Action Part I Hossein Rimaz K.N. Toosi University of Technology
  • 2. 2 Table of Contents • Why JavaFX and Use Cases • JavaFX App Architecture • Hello World • JavaFX Shapes • Recursive Graphic • Quick Introduction to Java 8 Lambda • Event-Driven Programming • Design Patterns and Observer • Properties & Bindings • Simple Graph Editor
  • 3. 3 Why JavaFX and Use Cases
  • 4. 4 History of JavaFX Using Google Trends JavaFX Script 1.0 JavaFX 2.0 JavaFX 8
  • 5. 5 Where can you use JavaFX? Basically everywhere! ● Desktop Applications ● Mobile (with Gluon Mobile) ● Web Application (require plug-ins but JPro doesn’t need any!) ● Embedded System (even ARM)
  • 7. 7 JavaFX Application Life cycle Each JavaFX application needs to extend the javafx.application.Application class, which defines the life cycle of an application. • Application.init() can be used to define and prepare everything before the application starts. • Application.start(Stage stage) is called to start the application. This method should be used to define the complete application and its view by adding a scene that defines the main window of the application. • Application.stop() is called once the application is closed.
  • 8. 8 Structure of a JavaFX Application
  • 9. 9 Strange Names? Not at all! Think about it as a theater stage! You have a stage; actors (Nodes) come into the scene and going out of it. And well this is a play, scene goes in and goes out! Just as simple as it is!
  • 11. 11 Creating a JavaFX Application
  • 12. 12
  • 13. 13
  • 14. 14 Final Result That was a simple hello world that probably you have no idea about it! But the result is actually pretty!
  • 16. 16 JavaFX Shapes Well, let’s start a little bit simpler. ● Let’s just draw lines!
  • 17. 17 Be careful about what package you are importing!
  • 18. 18 JavaFX Shapes How about adding some loops?
  • 22. 22 Recursive Graphics ● You learned recursive programming and now you can apply those techniques to achieve stunning visual arts!
  • 23. 23 Drawing a Tree Source code at: https://github.com/mhrimaz/RecursiveTreeFX
  • 24. 24 Sierpinski Carpet Source code at : https://github.com/mhrimaz/SierpinskiCarpetFX
  • 25. 25 Quick Introduction to Java 8 Lambda
  • 26. 26 Java 8 New Features ● Lambda expressions ● Method references ● Default Methods (Defender methods) ● A new Stream API. ● Optional ● A new Date/Time API. ● Nashorn, the new JavaScript engine ● Removal of the Permanent Generation ● and more…
  • 27. 27 Lambda Expression ● A primary goal of lambdas is to help address the lack in the Java language of a good way to express functional programming concepts.
  • 28. 28 Syntax ● There are two ways to specify lambda expressions. The following simple examples illustrate the general forms: (param1, param2, ...) -> expression; (param1, param2, ...) -> { /* code statements */ }; ● Another thing to note is that parameters can be optionally typed. The compiler will infer the type of the parameters depending on the context.
  • 29. 29 Why Lambda? ● In event handling lambda expressions will makes our codes shorter and more expressive. ● Now you can understand NetBeans starter code better.
  • 31. 31 What is Event-Driven Programming? ● Until now, you may only wrote your programs in imperative way. Your code flow was deterministic and run line after another. ● Event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or messages from other programs/threads. ● Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications that are centered on performing certain actions in response to user input.
  • 32. 32 Simple Example ● Simple scenario: mouse goes in, performs a double click and goes out.
  • 34. 34 What is Design Pattern? ● In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. ● Design patterns can speed up the development process by providing tested, proven development paradigms. ● In addition, patterns allow developers to communicate using well- known, well understood names for software interactions.
  • 35. 35 GoF 23 Design Patterns Creational patterns – Abstract Factory – Builder – Factory Method – Prototype – Singleton Structural patterns – Adapter – Bridge – Composite – Decorator – Façade – Flyweight – Proxy Behavioral patterns – Chain of responsibility – Command – Interpreter – Iterator – Mediator – Memento – Observer – State – Strategy – Template method – Visitor
  • 36. 36 Design Pattern and JavaFX ● Well you’ve used many of them in your development without knowing their names. ● Knowing about observer design pattern can help you to understand JavaFX Properties & Bindings and It’s Observable collections better. ● If you want to learn more Please read this book: Java Design Patterns by Vaskaran Sarcar
  • 37. 37 Observer Design Pattern ● GoF Definition: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. ● Concept: In this pattern, there are many observers (objects) which are observing a particular subject (object). Observers are basically interested and want to be notified when there is a change made inside that subject. So, they register themselves to that subject. When they lose interest in the subject they simply unregister from the subject. Sometimes this model is also referred to as the Publisher-Subscriber model.
  • 38. 38 Computer World Example ● In the world of computer science, consider a simple UI-based example, where this UI is connected with some database (or business logic). A user can execute some query through that UI and after searching the database, the result is reflected back in the UI. In most of the cases we segregate the UI with the database. If a change occurs in the database, the UI should be notified so that it can update its display according to the change.
  • 39. 39 UI Patterns ● Graphical user interfaces have become a familiar part of our software landscape, both as users and as developers. Looking at it from a design perspective they represent a particular set of problems in system design - problems that have led to a number of different but similar solutions. ● When developing GUI applications you will inevitably encounter UI architectural framework concepts such as model view controller (MVC), model view presenter (MVP), or model view view-model (MVVM).
  • 41. 41 Properties & Bindings ● Properties are basically wrapper objects for JavaFX-based object attributes such as String or Integer. Properties allow developers to add listener code to respond when the wrapped value of an object has changed or is flagged as invalid. Also, property objects can be bound to one another. ● Binding behavior allows properties to update or synchronize their values based on a changed value from another property.
  • 42. 42 Types of JavaFX Properties ● Read/Writable ● Read-Only ● JavaFX’s properties are wrapper objects holding actual values while providing change support, invalidation support, and binding capabilities. ● Some Property Classes: – javafx.beans.property.SimpleIntegerProperty – javafx.beans.property.ReadOnlyIntegerWrapper – javafx.beans.property.SimpleDoubleProperty – javafx.beans.property.ReadOnlyDoubleWrapper – javafx.beans.property.SimpleStringProperty – javafx.beans.property.ReadOnlyStringWrapper
  • 43. 43 Example Output: StringProperty Value = password1 observable = StringProperty [value: 1234] oldValue = password1 newValue = 1234
  • 44. 44 Bindings ● binding has the idea of at least two values (properties) being synchronized. This means that when a dependent variable changes, the other variable changes. ● JavaFX provides many binding options that enable the developer to synchronize between properties in domain objects and GUI controls.
  • 45. 45 Types of JavaFX Bindings ● Simple Binding ● Bidirectional Binding
  • 46. 46 Example ● Binding String length to a Integer Property
  • 47. 47 Simple Graph Editor Source code at: https://github.com/mhrimaz/JavaFXWorkshop_01