1
Lecture 1: Introduction to
JavaFX
Shima Muhammad Qhafor
UHD / College Of Science & Technology
Computer Science Department
Computer Graphics – Practicum
What is JavaFX?
2
Is used to build Rich Internet Applications(RIA).
The applications can run across multiple platforms.
To develop GUI Applications using Java programming
language
Previously:
rely on libraries such as AWT and Swing.
Now: develop GUI applications effectively with rich
content.
Features of JavaFX
3
Written in Java − applications are also platform independent.
FXML − is a HTML like declarative markup language.
Scene Builder − the users can access a drag and drop design interface.
Swing Interoperability − you can embed Swing content.
Built-in UI controls − you can develop a full-featured application.
CSS like Styling − you can improve the design of your application.
Canvas and Printing API − JavaFX provides Canvas, an immediate
mode style of rendering API. javafx.scene.canvas and javafx.print
Packages.
Rich set of API’s − provides a rich set of API’s to develop GUI
applications, 2D and 3D graphics, etc.
Graphics pipeline − supports graphics based on the Hardware-
accelerated graphics pipeline known as Prism.
JavaFX Architecture
4
• Glass Windowing Toolkit: Provides native operating services, such as managing
the windows, timers, and surfaces
• Prism: Graphics pipeline that can run on hardware and software renderers.
• Quantum Toolkit: Ties Prism and Glass together and makes them available to
the JavaFX APIs.
JavaFX Public API’s and Scene Graph
Quantum Toolkit
Prism
JavaFX Glass Windowing Media Web
Graphics Engine Java Open Toolkit Engine Engine
D3D
2D GL
Java Virtual Machine
JavaFX Architecture (Cont.)
5
Prism is designed to take advantage of the latest GPUs to
provide hardware accelerated graphics and minimize the
load on the CPU.
On systems where there is no compatible GPU, Prism uses
render path to process the graphics. So your JavaFX
applications can continue to run even on older systems or
systems with less resources.
Softwares
6
Download JDK 8 with JavaFX 8 from
http://www.oracle.com/technetwork/java/javase/
downloads
IDE:
Netbeans: download (Netbeans 8.2) from
https://netbeans.org/downloads/
Or Eclipse
Creating First JavaFX Application (1)
7
File New Project
Creating First JavaFX Application (2)
8
Select (JavaFX) click Next
Creating First JavaFX Application (3)
9
Choose a name for your project click Finish
Creating First JavaFX Application (4)
10
Run your program
Creating First JavaFX Application (5)
11
import javafx.application.Application; resizable
layout node
…
public class JAVAFXTEST extends Application { StackPane root = new StackPane();
@Override top-level
root.getChildren().add(btn);
main container
entry public void start(Stage primaryStage) { for all
point Button btn = new Button(); content Scene scene = new Scene(root, 300, 250);
btn.setText("Say 'Hello World'"); primaryStage.setTitle("Hello World!");
btn.setOnAction(new EventHandler<ActionEvent>() { primaryStage.setScene(scene);
@Override primaryStage.show();
public void handle(ActionEvent event) { }
System.out.println("Hello World!"); public static void main(String[] args) {
} launch(args);
}); }
**the content of
} the scene is
represented as a
hierarchical scene
Now Add another stage with a button to the same program graph of nodes
JavaFX Program Basic Structure
12
public class MyProgram
{
// Body of class
}
Becomes:
import javafx.application.Application;
…
public class MyProgram extends Application
{
// Body of class
}
JavaFX Program Layout
13
Stage – This is the outer shell of your application and contains the entire
program
Scene – The object directly contained by the stage. In the program when
you want to switch to another view you can also have the Stage change to
a different Scene.
The Root Pane/Container – This object holds all the parts of the application,
like buttons, labels, textfields, etc.
14