Introduction To Javafx: A Rich Client Platform For All Screens
Introduction To Javafx: A Rich Client Platform For All Screens
Introduction To Javafx: A Rich Client Platform For All Screens
Richard Bair
Sun Microsystems, Inc.
A rich client platform for all screens
Introduction to JavaFX
• JavaFX is the next generation client stack for the Java Platform
> Consumer & Enterprise
> Consistent cross-device API and development model
• Designed for high performance graphics on desktop, mobile, tv
> Leverages OpenGL, Direct3D, SSE3 when possible on any target device
> Ground-up rewrite of fonts, image handling, rasterization
• Designed for multi-language support
> Java
> JavaFX Script
> more...
Outline
Expression Language
Object Oriented
JVM Language
Strongly Typed
Type Inference
• A programming language is not about telling the computer what to do, but
instead is about expressing the programmer’s intent.
• A programming language needs to embody new, higher-level concepts and to
abstract away irrelevant detail. (Brooks 1993, HOPL-II keynote)
• JavaFX Script is tightly integrated with, and works extremely effectively with
the JavaFX runtime and scenegraph
• Itʼs fun!
println(“Hello, world!”)
def PI = 3.14159265;
var name:String;
name = “Richard”;
Data Types
Sequences
for (x in [1..5]) {
x * x
}
Object Literals
when leftMargin
var leftMargin = 472; changes the x-value
of both Rectangles
changes
var r1 = Rectangle {
x: bind leftMargin
...
};
var r2 = Rectangle {
x: bind leftMargin
...
}
Outline
Scenegraph
Group
Image Group
Circle Media
Scenegraph Sample
Group {
content: [
ImageView { } Group
Group {
content: [
Circle { },
MediaView { } Image Group
]
}
]
} Circle Media
Nodes
• Group • MediaView
• CustomNode • Text
• Container • more...
• Control
• Line
• Path
• Rectangle
• ImageView
ImageView
Text Node
• x, y, TextOrigin
• Fonts can be specified on Text
• Supports multiline text
• By default, text positioned such that (x, y) is left baseline
(0, -10)
(0, 0)
Example
2009 Sun Microsystems, Incorporated. All Rights Reserved.
A rich client platform for all screens
Effects
Media
Animation
KeyFrame Animation
Timeline {
keyFrames: at (4s) { text.rotate => 210.0 }
}.play();
Transitions
Outline
JavaFX UI Controls
• Simple
• Useful
• Rich
Architecture
Skin
Control
Behavior
Dark color
buttons on
toolbar
Light color
controls on
almost white
background
Controls in JavaFX
Button
• action:function()
• Example:
Button {
text: “Cancel”
action: function() {
println(“I’ve been clicked!”);
}
}
Progress Indicator
• progress:Number (0..1)
• progress bar is-a progress indicator
• Example:
var task = HttpRequest { ... }
ProgressIndicator { progress: bind task.percentDone }
TextBox
• text:String
• promptText:String
• font:Font
• action:function()
• Example:
var t:TextBox = TextBox {
promptText: “Search”
action: function() {
startSearch(t.text);
t.text = “”;
}
}
Multiline TextBox
• columns:Integer
• lines:Integer
• multiline:Boolean
• Example:
var t:TextBox = TextBox {
columns: 30
lines: 10
multiline: true
}
List View
• Horizontal or Vertical
• Massively Scalable
• Custom Cells
• Dynamically variable row height
• Example:
ListView {
items: [“Apples”, “Oranges”, “Bananas”]
cellMaker: function() {
ListCell { ... }
}
}
DEMO – UI Controls
Outline
Styling
Styling
Styling
Styling
Styling
Styling
Outline
Charts
Pie Chart
Sample Pie
PieChart {
title: "Sample Pie"
data: [
PieChart.Data {
label: "Apples" value: 34
action: function(){ Alert.inform("Clicked") }
},
PieChart.Data { label: "Oranges" value: 27 },
PieChart.Data { label: "Bananas" value: 16 },
PieChart.Data { label: "Grapes" value: 50 },
PieChart.Data { label: "Cherries" value: 6 },
PieChart.Data { label: "Strawberry" value: 5 },
PieChart.Data { label: "Raspberry" value: 7 }
]
}
Bar Chart
Line Chart
Area Chart
Scatter Chart
Bubble Chart
3D Bar Chart
3D Pie Chart
Outline
Layout Containers
• Container-based layout
• Container is-a Node
• Built-in Containers in 1.2
> Stack: stack all content nodes on top of each other
> HBox: lay out content horizontally
> VBox: lay out content vertically
> Flow: layout out content either horizontally or vertically and line wrap
> Panel: Customizable layout container
Flow Sample
Flow {
width: 800
height: 600
content: for (img in images) {
ImageView { image: img }
}
}
Developer Tools
Developer-Designer Workflow
Call To Action
• fxexperience.com
• Visit javafx.com
> Download JavaFX SDK + NetBeans
> See demos
> Download example code
> Read tutorials, FAQs, white papers, documentation
> Browse API Documentation
Thank You!