SlideShare a Scribd company logo
Raspberry Pi à la GroovyFX
Stephen Chin (@steveonjava)
Java Technology Ambassador
JavaOne Content Chair
What Runs Java?
Example of devices powered by Java
SMALL
 RFID Readers
 Parking Meters
 Intelligent Power
Module
 Smart Meters
LARGE
 Multi Function Printers
 ATMs
 POS Systems
 In-Flight Entertainment Systems
 Electronic Voting Systems
 Medical Imaging Systems
MEDIUM
 Routers & Switches
 Storage Appliances
 Network Management
Systems
 Factory Automation Systems
 Security Systems
Java and 3G in a Tiny Package
> Cinterion EHS5
Really Tiny…
27.6mm
18.8mm
http://upload.wikimedia.org/wikipedia/commons/3/3d/Cloud_forest_Ecuador.jpg
=
Have Java With Your Dessert
http://elinux.org/File:Raspi-Model-AB-Mono-2-699x1024.png
And what are these for?
http://i.imgur.com/k0Puu.jpg
I2C Hardware via Pi4J
3.3V/GND
MPU-9150
Chalkboard Electronics Touchscreen
 10" or 7" Form Factor
 Connects via HDMI/USB
 Tested with JavaFX 8
 10% Exclusive Discount:
G1F0U796Z083
How to Setup Your Pi
> Step 1: Install Linux
http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
How to Setup Your Pi
> Step 2: Download/Copy Java 8 for ARM EA
http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
How to Setup Your Pi
> Step 3: Deploy and Run JavaFX Apps
http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
JavaFX With Groovy
JavaFX 2.0 Platform
Immersive Application Experience
Leverage your Java skills with modern JavaFX
APIs
> Cross-platform Animation, Video, Charting
> Integrate Java, JavaScript, and HTML5 in the
same application
> New graphics stack takes advantage of
hardware acceleration for 2D and 3D
applications
> Use your favorite IDE:
NetBeans, Eclipse, IntelliJ, etc.
16
Vanishing Circles
Vanishing Circles in Java
public class VanishingCircles extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Vanishing Circles");
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.BLACK);
List<Circle> circles = new ArrayList<Circle>();
for (int i = 0; i < 50; i++) {
final Circle circle = new Circle(150);
circle.setCenterX(Math.random() * 800);
circle.setCenterY(Math.random() * 600);
circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2));
circle.setEffect(new BoxBlur(10, 10, 3));
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
public void handle(MouseEvent t) {
KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);
new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play();
}
});
circle.setStroke(Color.WHITE);
circle.strokeWidthProperty().bind(Bindings.when(circle.hoverProperty())
.then(4)
.otherwise(0));
circles.add(circle);
}
root.getChildren().addAll(circles);
primaryStage.setScene(scene);
primaryStage.show();
Timeline moveCircles = new Timeline();
for (Circle circle : circles) {
KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800);
KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600);
moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY));
}
moveCircles.play();
}
}
17
40 Lines
1299 Characters
Application Skeleton
public class VanishingCircles extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Vanishing Circles");
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.BLACK);
[create the circles…]
root.getChildren().addAll(circles);
primaryStage.setScene(scene);
primaryStage.show();
[begin the animation…]
}
}
Create the Circles
List<Circle> circles = new ArrayList<Circle>();
for (int i = 0; i < 50; i++) {
final Circle circle = new Circle(150);
circle.setCenterX(Math.random() * 800);
circle.setCenterY(Math.random() * 600);
circle.setFill(new Color(Math.random(), Math.random(),
Math.random(), .2));
circle.setEffect(new BoxBlur(10, 10, 3));
circle.setStroke(Color.WHITE);
[setup binding…]
[setup event listeners…]
circles.add(circle);
}
19
Setup Binding
circle.strokeWidthProperty().bind(Bindings
.when(circle.hoverProperty())
.then(4)
.otherwise(0)
);
20
Setup Event Listeners
circle.addEventHandler(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent t) {
KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);
new Timeline(new KeyFrame(Duration.seconds(3),
collapse)).play();
}
});
21
Begin the Animation
Timeline moveCircles = new Timeline();
for (Circle circle : circles) {
KeyValue moveX = new KeyValue(circle.centerXProperty(),
Math.random() * 800);
KeyValue moveY = new KeyValue(circle.centerYProperty(),
Math.random() * 600);
moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40),
moveX, moveY));
}
moveCircles.play();
22
Features of Groovy
> Modern language
 Closures
 AST Transforms
 Strongly typed dynamic language
> Tight integration with Java
 Very easy to port from Java to Groovy
> Declarative syntax with GroovyFX Builders
 Familiar to Groovy and JavaFX Script developers
Java vs. GroovyFX DSL
public class VanishingCircles extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Vanishing Circles");
Group root = new Group();
Scene scene = new Scene(root, 800, 600, Color.BLACK);
List<Circle> circles = new ArrayList<Circle>();
for (int i = 0; i < 50; i++) {
final Circle circle = new Circle(150);
circle.setCenterX(Math.random() * 800);
circle.setCenterY(Math.random() * 600);
circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2));
circle.setEffect(new BoxBlur(10, 10, 3));
circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
public void handle(MouseEvent t) {
KeyValue collapse = new KeyValue(circle.radiusProperty(), 0);
new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play();
}
});
circle.setStroke(Color.WHITE);
circle.strokeWidthProperty().bind(Bindings.when(circle.hoverProperty())
.then(4)
.otherwise(0));
circles.add(circle);
}
root.getChildren().addAll(circles);
primaryStage.setScene(scene);
primaryStage.show();
Timeline moveCircles = new Timeline();
for (Circle circle : circles) {
KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800);
KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600);
moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY));
}
moveCircles.play();
}
}
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
onMouseClicked { e ->
timeline {
at(3.s) { change e.source.radiusProperty() to 0 }
}.play()
}
}
}
}
timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) {
circles.each { circle ->
at (40.s) {
change circle.centerXProperty() to rand(800)
change circle.centerYProperty() to rand(600)
}
}
}.play()
}
}
24
40 Lines
1299 Characters
29 Lines
671 Characters
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
25
26
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
Builder for GroovyFX scene graphs
27
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
Declarative Stage definition
28
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
Inline property definitions
29
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
Bind to properties
30
GroovyFX.start { primaryStage ->
def sg = new SceneGraphBuilder()
def rand = new Random().&nextInt
def circles = []
sg.stage(title: 'Vanishing Circles', show: true) {
scene(fill: black, width: 800, height: 600) {
50.times {
circles << circle(centerX: rand(800), centerY: rand(600),
radius: 150, stroke: white,
strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) {
fill rgb(rand(255), rand(255), rand(255), 0.2)
effect boxBlur(width: 10, height: 10, iterations: 3)
}
}
}
}
}
Sequence Creation Via Loop
Animation in GroovyFX
timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) {
circles.each { circle ->
at (40.s) {
change circle.centerXProperty() to rand(800)
change circle.centerYProperty() to rand(600)
}
}
}.play()
31
timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) {
circles.each { circle ->
at (40.s) {
change circle.centerXProperty() to rand(800)
change circle.centerYProperty() to rand(600)
}
}
}.play()
Animation in GroovyFX
32
Easy animation syntax:
at (duration) {keyframes}
timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) {
circles.each { circle ->
at (40.s) {
change circle.centerXProperty() to rand(800)
change circle.centerYProperty() to rand(600)
}
}
}.play()
Animation in GroovyFX
33
Key frame DSL
timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) {
circles.each { circle ->
at (40.s) {
tween ease_both
change circle.centerYProperty() to rand(600) tween linear
}
}
}.play()
Animation in GroovyFX
34
Optional easing
Event Listeners in GroovyFX
35
> Supported using the built-in Closure syntax
> Optional arguments for event objects
onMouseClicked { e ->
timeline {
at(3.s) { change e.source.radiusProperty() to 0 }
}.play()
}
Event Listeners in GroovyFX
> Supported using the built-in Closure syntax
> Optional arguments for event objects
36
Compact syntax
{body}
onMouseClicked { MouseEvent e ->
timeline {
at(3.s) { change e.source.radiusProperty() to 0 }
}.play()
}
Event Listeners in GroovyFX
> Supported using the built-in Closure syntax
> Optional arguments for event objects
37
Optional event parameter
{event -> body}
onMouseClicked { MouseEvent e ->
timeline {
at(3.s) { change e.source.radiusProperty() to 0 }
}.play()
}
38
But wait, there is more Grooviness…
Properties in Java
public class Person {
private StringProperty firstName;
public void setFirstName(String val) { firstNameProperty().set(val); }
public String getFirstName() { return firstNameProperty().get(); }
public StringProperty firstNameProperty() {
if (firstName == null)
firstName = new SimpleStringProperty(this, "firstName");
return firstName;
}
private StringProperty lastName;
public void setLastName(String value) { lastNameProperty().set(value); }
public String getLastName() { return lastNameProperty().get(); }
public StringProperty lastNameProperty() {
if (lastName == null) // etc.
}
}
39
Properties in GroovyFX
public class Person {
@FXBindable String firstName;
@FXBindable String lastName;
}
40
public class Person {
@FXBindable String firstName;
@FXBindable String lastName = “Smith”;
}
Properties in GroovyFX
41
Optional initializers
TableView in Java
42
ObservableList<Person> items = ...
TableView<Person> tableView = new TableView<Person>(items);
TableColumn<Person,String> firstNameCol =
new TableColumn<Person,String>("First Name");
firstNameCol.setCellValueFactory(
new Callback<CellDataFeatures<Person, String>,
ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Person, String> p)
{
return p.getValue().firstNameProperty();
}
});
tableView.getColumns().add(firstNameCol);
TableView in GroovyFX
43
def dateFormat = new SimpleDateFormat("yyyy-MM-dd");
tableView(items: persons) {
tableColumn(property: "name", text: "Name", prefWidth: 150)
tableColumn(property: "age", text: "Age", prefWidth: 50)
tableColumn(property: "gender", text: "Gender", prefWidth: 150)
tableColumn(property: "dob", text: "Birth", prefWidth: 150,
type: Date,
converter: { from -> return dateFormat.format(from) })
}
Layout in Java
44
TextField urlField = new TextField(“http://www.google.com”);
HBox.setHgrow(urlField, Priority.ALWAYS);
HBox hbox = new HBox();
hbox.getChildren().add(urlField);
WebView webView = new WebView();
VBox.setVgrow(webView, Priority.ALWAYS);
VBox vbox = new VBox();
vbox.getChildren().addAll(hbox, webView);
Layout in GroovyFX
45
sg.stage(title: "GroovyFX WebView Demo", show: true) {
scene(fill: groovyblue, width: 1024, height: 800) {
vbox {
hbox(padding: 10, spacing: 5) {
textField(“http://www.yahoo.com”, hgrow: "always")
button("Go”)
}
webView(vgrow: "always")
}
}
}
Layout in GroovyFX
46
Layout in GroovyFX
47
gridPane(hgap: 5, vgap: 10, padding: 25) {
columnConstraints(minWidth: 50, halignment: "right")
columnConstraints(prefWidth: 250)
label("Send Us Your Feedback", font: "24pt sanserif",
row: 0, columnSpan: GridPane.REMAINING, halignment: "center",
margin: [0, 0, 10])
label("Name: ", row: 1, column: 0)
textField(promptText: "Your name", row: 1, column: 1, hgrow: 'always')
label("Email:", row: 2, column: 0)
textField(promptText: "Your email", row: 2, column: 1, hgrow: 'always')
label("Message:", row: 3, column: 0, valignment: "baseline")
textArea(row: 3, column: 1, hgrow: "always", vgrow: "always")
button("Send Message", row: 4, column: 1, halignment: "right")
}
Layout in GroovyFX
48
GroovyFX Supports…
49
And you can do cool stuff like this…
https://bitbucket.org/stephanj/tweetwall
Conclusion
 JavaFX enables graphically rich, fast performing apps
 Visually create applications using Scene Builder
 Run on Raspberry Pi today!
Stephen Chin
tweet: @steveonjava
blog: http://steveonjava.com
nighthacking.com
Real Geeks
Live Hacking
NightHacking Tour
The preceding is intended to outline our general product direction. It is
intended
for information purposes only, and may not be incorporated into any contract.
It is not a commitment to deliver any material, code, or functionality, and
should not be relied upon in making purchasing decisions. The development,
release, and timing of any features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.

More Related Content

PDF
The Ring programming language version 1.8 book - Part 59 of 202
PDF
The Ring programming language version 1.7 book - Part 57 of 196
PDF
The Ring programming language version 1.8 book - Part 53 of 202
PPTX
Making Games in JavaScript
PDF
The Ring programming language version 1.2 book - Part 35 of 84
KEY
Introduction to Game Programming Tutorial
KEY
Intro to Game Programming
PDF
Exploring Canvas
The Ring programming language version 1.8 book - Part 59 of 202
The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.8 book - Part 53 of 202
Making Games in JavaScript
The Ring programming language version 1.2 book - Part 35 of 84
Introduction to Game Programming Tutorial
Intro to Game Programming
Exploring Canvas

What's hot (20)

PDF
The Ring programming language version 1.5.2 book - Part 52 of 181
PDF
The Ring programming language version 1.5.2 book - Part 66 of 181
PDF
A promise is a Promise
ODP
Creating masterpieces with raphael
PDF
The Ring programming language version 1.5 book - Part 9 of 31
PDF
Prelude to halide_public
PDF
Node meetup feb_20_12
PDF
The Ring programming language version 1.6 book - Part 55 of 189
PDF
The Ring programming language version 1.3 book - Part 42 of 88
PDF
The Ring programming language version 1.9 book - Part 62 of 210
PDF
PDF
The Ring programming language version 1.10 book - Part 70 of 212
PDF
PyCon2009_AI_Alt
PPTX
Wrangle 2016: (Lightning Talk) FizzBuzz in TensorFlow
PDF
The Ring programming language version 1.7 book - Part 63 of 196
PDF
The Ring programming language version 1.5.3 book - Part 62 of 184
PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
The Ring programming language version 1.3 book - Part 43 of 88
PDF
The Ring programming language version 1.5.4 book - Part 53 of 185
PDF
The Ring programming language version 1.5.1 book - Part 49 of 180
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181
A promise is a Promise
Creating masterpieces with raphael
The Ring programming language version 1.5 book - Part 9 of 31
Prelude to halide_public
Node meetup feb_20_12
The Ring programming language version 1.6 book - Part 55 of 189
The Ring programming language version 1.3 book - Part 42 of 88
The Ring programming language version 1.9 book - Part 62 of 210
The Ring programming language version 1.10 book - Part 70 of 212
PyCon2009_AI_Alt
Wrangle 2016: (Lightning Talk) FizzBuzz in TensorFlow
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.5.3 book - Part 62 of 184
The Ring programming language version 1.9 book - Part 60 of 210
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.5.4 book - Part 53 of 185
The Ring programming language version 1.5.1 book - Part 49 of 180
Ad

Viewers also liked (20)

PDF
Mary Had a Little λ (QCon)
PPTX
JCrete Embedded Java Workshop
PPTX
Confessions of a Former Agile Methodologist
PPTX
Internet of Things Magic Show
PPTX
Raspberry Pi with Java (JJUG)
PPTX
JavaFX and Scala in the Cloud
PPTX
Java on Raspberry Pi Lab
PDF
DukeScript
PPTX
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
PPTX
Zombie Time - JSR 310 for the Undead
PDF
Raspberry Pi Gaming 4 Kids - Dutch Version
PPTX
Raspberry pi gaming 4 kids
PPTX
RetroPi Handheld Raspberry Pi Gaming Console
PPTX
OpenJFX on Android and Devices
PPTX
JavaFX on Mobile (by Johan Vos)
PPTX
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
PPTX
Confessions of a Former Agile Methodologist (JFrog Edition)
PPTX
Oracle IoT Kids Workshop
PDF
Java 8 for Tablets, Pis, and Legos
PPTX
Devoxx4Kids NAO Workshop
Mary Had a Little λ (QCon)
JCrete Embedded Java Workshop
Confessions of a Former Agile Methodologist
Internet of Things Magic Show
Raspberry Pi with Java (JJUG)
JavaFX and Scala in the Cloud
Java on Raspberry Pi Lab
DukeScript
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Zombie Time - JSR 310 for the Undead
Raspberry Pi Gaming 4 Kids - Dutch Version
Raspberry pi gaming 4 kids
RetroPi Handheld Raspberry Pi Gaming Console
OpenJFX on Android and Devices
JavaFX on Mobile (by Johan Vos)
Raspberry Pi Gaming 4 Kids (Devoxx4Kids)
Confessions of a Former Agile Methodologist (JFrog Edition)
Oracle IoT Kids Workshop
Java 8 for Tablets, Pis, and Legos
Devoxx4Kids NAO Workshop
Ad

Similar to Raspberry Pi à la GroovyFX (20)

PPTX
JavaFX and Scala - Like Milk and Cookies
PDF
Create a java project that - Draw a circle with three random init.pdf
KEY
Proga 0706
PPTX
ES6(ES2015) is beautiful
DOCX
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
PDF
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
PDF
The Ring programming language version 1.5.2 book - Part 64 of 181
PDF
The Ring programming language version 1.5.3 book - Part 70 of 184
PDF
Creating an Uber Clone - Part IV.pdf
PPTX
HTML5 Canvas (Wall Clock).pptx
PDF
The Ring programming language version 1.10 book - Part 54 of 212
PDF
package chapter15;import javafx.application.Application;import j.pdf
PDF
The Ring programming language version 1.5.2 book - Part 29 of 181
PDF
The Ring programming language version 1.4 book - Part 8 of 30
PDF
Assignment7.pdf
PPTX
JavaFX 2.0 With Alternative Languages - JavaOne 2011
PDF
ECMAScript 6 major changes
PDF
The Ring programming language version 1.7 book - Part 48 of 196
PDF
You are task to add a yawning detection to the programme below;i.pdf
PPTX
ScalaDays 2014 - Reactive Scala 3D Game Engine
JavaFX and Scala - Like Milk and Cookies
Create a java project that - Draw a circle with three random init.pdf
Proga 0706
ES6(ES2015) is beautiful
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
Hacking JavaFX with Groovy, Clojure, Scala, and Visage: Stephen Chin
The Ring programming language version 1.5.2 book - Part 64 of 181
The Ring programming language version 1.5.3 book - Part 70 of 184
Creating an Uber Clone - Part IV.pdf
HTML5 Canvas (Wall Clock).pptx
The Ring programming language version 1.10 book - Part 54 of 212
package chapter15;import javafx.application.Application;import j.pdf
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.4 book - Part 8 of 30
Assignment7.pdf
JavaFX 2.0 With Alternative Languages - JavaOne 2011
ECMAScript 6 major changes
The Ring programming language version 1.7 book - Part 48 of 196
You are task to add a yawning detection to the programme below;i.pdf
ScalaDays 2014 - Reactive Scala 3D Game Engine

More from Stephen Chin (10)

PPTX
DevOps Tools for Java Developers v2
PPTX
10 Ways Everyone Can Support the Java Community
PPTX
Java Clients and JavaFX: The Definitive Guide
PPTX
DevOps Tools for Java Developers
PPTX
Java Clients and JavaFX - Presented to LJC
PPTX
Devoxx4Kids Lego Workshop
PPTX
LUGOD Raspberry Pi Hacking
PPTX
Moving to the Client - JavaFX and HTML5
PPTX
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
PPTX
JavaFX 2 Using the Spring Framework
DevOps Tools for Java Developers v2
10 Ways Everyone Can Support the Java Community
Java Clients and JavaFX: The Definitive Guide
DevOps Tools for Java Developers
Java Clients and JavaFX - Presented to LJC
Devoxx4Kids Lego Workshop
LUGOD Raspberry Pi Hacking
Moving to the Client - JavaFX and HTML5
JavaFX 2 - A Java Developer's Guide (San Antonio JUG Version)
JavaFX 2 Using the Spring Framework

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
KodekX | Application Modernization Development
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
KodekX | Application Modernization Development
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Mobile App Security Testing_ A Comprehensive Guide.pdf
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
Chapter 3 Spatial Domain Image Processing.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Raspberry Pi à la GroovyFX

  • 1. Raspberry Pi à la GroovyFX Stephen Chin (@steveonjava) Java Technology Ambassador JavaOne Content Chair
  • 2. What Runs Java? Example of devices powered by Java SMALL  RFID Readers  Parking Meters  Intelligent Power Module  Smart Meters LARGE  Multi Function Printers  ATMs  POS Systems  In-Flight Entertainment Systems  Electronic Voting Systems  Medical Imaging Systems MEDIUM  Routers & Switches  Storage Appliances  Network Management Systems  Factory Automation Systems  Security Systems
  • 3. Java and 3G in a Tiny Package > Cinterion EHS5
  • 6. = Have Java With Your Dessert
  • 8. And what are these for? http://i.imgur.com/k0Puu.jpg
  • 9. I2C Hardware via Pi4J 3.3V/GND MPU-9150
  • 10. Chalkboard Electronics Touchscreen  10" or 7" Form Factor  Connects via HDMI/USB  Tested with JavaFX 8  10% Exclusive Discount: G1F0U796Z083
  • 11. How to Setup Your Pi > Step 1: Install Linux http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
  • 12. How to Setup Your Pi > Step 2: Download/Copy Java 8 for ARM EA http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
  • 13. How to Setup Your Pi > Step 3: Deploy and Run JavaFX Apps http://steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
  • 15. JavaFX 2.0 Platform Immersive Application Experience Leverage your Java skills with modern JavaFX APIs > Cross-platform Animation, Video, Charting > Integrate Java, JavaScript, and HTML5 in the same application > New graphics stack takes advantage of hardware acceleration for 2D and 3D applications > Use your favorite IDE: NetBeans, Eclipse, IntelliJ, etc.
  • 17. Vanishing Circles in Java public class VanishingCircles extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Vanishing Circles"); Group root = new Group(); Scene scene = new Scene(root, 800, 600, Color.BLACK); List<Circle> circles = new ArrayList<Circle>(); for (int i = 0; i < 50; i++) { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { KeyValue collapse = new KeyValue(circle.radiusProperty(), 0); new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play(); } }); circle.setStroke(Color.WHITE); circle.strokeWidthProperty().bind(Bindings.when(circle.hoverProperty()) .then(4) .otherwise(0)); circles.add(circle); } root.getChildren().addAll(circles); primaryStage.setScene(scene); primaryStage.show(); Timeline moveCircles = new Timeline(); for (Circle circle : circles) { KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800); KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600); moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY)); } moveCircles.play(); } } 17 40 Lines 1299 Characters
  • 18. Application Skeleton public class VanishingCircles extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Vanishing Circles"); Group root = new Group(); Scene scene = new Scene(root, 800, 600, Color.BLACK); [create the circles…] root.getChildren().addAll(circles); primaryStage.setScene(scene); primaryStage.show(); [begin the animation…] } }
  • 19. Create the Circles List<Circle> circles = new ArrayList<Circle>(); for (int i = 0; i < 50; i++) { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.setStroke(Color.WHITE); [setup binding…] [setup event listeners…] circles.add(circle); } 19
  • 21. Setup Event Listeners circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { KeyValue collapse = new KeyValue(circle.radiusProperty(), 0); new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play(); } }); 21
  • 22. Begin the Animation Timeline moveCircles = new Timeline(); for (Circle circle : circles) { KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800); KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600); moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY)); } moveCircles.play(); 22
  • 23. Features of Groovy > Modern language  Closures  AST Transforms  Strongly typed dynamic language > Tight integration with Java  Very easy to port from Java to Groovy > Declarative syntax with GroovyFX Builders  Familiar to Groovy and JavaFX Script developers
  • 24. Java vs. GroovyFX DSL public class VanishingCircles extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Vanishing Circles"); Group root = new Group(); Scene scene = new Scene(root, 800, 600, Color.BLACK); List<Circle> circles = new ArrayList<Circle>(); for (int i = 0; i < 50; i++) { final Circle circle = new Circle(150); circle.setCenterX(Math.random() * 800); circle.setCenterY(Math.random() * 600); circle.setFill(new Color(Math.random(), Math.random(), Math.random(), .2)); circle.setEffect(new BoxBlur(10, 10, 3)); circle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { KeyValue collapse = new KeyValue(circle.radiusProperty(), 0); new Timeline(new KeyFrame(Duration.seconds(3), collapse)).play(); } }); circle.setStroke(Color.WHITE); circle.strokeWidthProperty().bind(Bindings.when(circle.hoverProperty()) .then(4) .otherwise(0)); circles.add(circle); } root.getChildren().addAll(circles); primaryStage.setScene(scene); primaryStage.show(); Timeline moveCircles = new Timeline(); for (Circle circle : circles) { KeyValue moveX = new KeyValue(circle.centerXProperty(), Math.random() * 800); KeyValue moveY = new KeyValue(circle.centerYProperty(), Math.random() * 600); moveCircles.getKeyFrames().add(new KeyFrame(Duration.seconds(40), moveX, moveY)); } moveCircles.play(); } } GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) onMouseClicked { e -> timeline { at(3.s) { change e.source.radiusProperty() to 0 } }.play() } } } } timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) { circles.each { circle -> at (40.s) { change circle.centerXProperty() to rand(800) change circle.centerYProperty() to rand(600) } } }.play() } } 24 40 Lines 1299 Characters 29 Lines 671 Characters
  • 25. GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } 25
  • 26. 26 GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } Builder for GroovyFX scene graphs
  • 27. 27 GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } Declarative Stage definition
  • 28. 28 GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } Inline property definitions
  • 29. 29 GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } Bind to properties
  • 30. 30 GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() def rand = new Random().&nextInt def circles = [] sg.stage(title: 'Vanishing Circles', show: true) { scene(fill: black, width: 800, height: 600) { 50.times { circles << circle(centerX: rand(800), centerY: rand(600), radius: 150, stroke: white, strokeWidth: bind('hover', converter: {val -> val ? 4 : 0})) { fill rgb(rand(255), rand(255), rand(255), 0.2) effect boxBlur(width: 10, height: 10, iterations: 3) } } } } } Sequence Creation Via Loop
  • 31. Animation in GroovyFX timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) { circles.each { circle -> at (40.s) { change circle.centerXProperty() to rand(800) change circle.centerYProperty() to rand(600) } } }.play() 31
  • 32. timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) { circles.each { circle -> at (40.s) { change circle.centerXProperty() to rand(800) change circle.centerYProperty() to rand(600) } } }.play() Animation in GroovyFX 32 Easy animation syntax: at (duration) {keyframes}
  • 33. timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) { circles.each { circle -> at (40.s) { change circle.centerXProperty() to rand(800) change circle.centerYProperty() to rand(600) } } }.play() Animation in GroovyFX 33 Key frame DSL
  • 34. timeline(cycleCount: Timeline.INDEFINITE, autoReverse: true) { circles.each { circle -> at (40.s) { tween ease_both change circle.centerYProperty() to rand(600) tween linear } } }.play() Animation in GroovyFX 34 Optional easing
  • 35. Event Listeners in GroovyFX 35 > Supported using the built-in Closure syntax > Optional arguments for event objects onMouseClicked { e -> timeline { at(3.s) { change e.source.radiusProperty() to 0 } }.play() }
  • 36. Event Listeners in GroovyFX > Supported using the built-in Closure syntax > Optional arguments for event objects 36 Compact syntax {body} onMouseClicked { MouseEvent e -> timeline { at(3.s) { change e.source.radiusProperty() to 0 } }.play() }
  • 37. Event Listeners in GroovyFX > Supported using the built-in Closure syntax > Optional arguments for event objects 37 Optional event parameter {event -> body} onMouseClicked { MouseEvent e -> timeline { at(3.s) { change e.source.radiusProperty() to 0 } }.play() }
  • 38. 38 But wait, there is more Grooviness…
  • 39. Properties in Java public class Person { private StringProperty firstName; public void setFirstName(String val) { firstNameProperty().set(val); } public String getFirstName() { return firstNameProperty().get(); } public StringProperty firstNameProperty() { if (firstName == null) firstName = new SimpleStringProperty(this, "firstName"); return firstName; } private StringProperty lastName; public void setLastName(String value) { lastNameProperty().set(value); } public String getLastName() { return lastNameProperty().get(); } public StringProperty lastNameProperty() { if (lastName == null) // etc. } } 39
  • 40. Properties in GroovyFX public class Person { @FXBindable String firstName; @FXBindable String lastName; } 40
  • 41. public class Person { @FXBindable String firstName; @FXBindable String lastName = “Smith”; } Properties in GroovyFX 41 Optional initializers
  • 42. TableView in Java 42 ObservableList<Person> items = ... TableView<Person> tableView = new TableView<Person>(items); TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name"); firstNameCol.setCellValueFactory( new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() { public ObservableValue<String> call(CellDataFeatures<Person, String> p) { return p.getValue().firstNameProperty(); } }); tableView.getColumns().add(firstNameCol);
  • 43. TableView in GroovyFX 43 def dateFormat = new SimpleDateFormat("yyyy-MM-dd"); tableView(items: persons) { tableColumn(property: "name", text: "Name", prefWidth: 150) tableColumn(property: "age", text: "Age", prefWidth: 50) tableColumn(property: "gender", text: "Gender", prefWidth: 150) tableColumn(property: "dob", text: "Birth", prefWidth: 150, type: Date, converter: { from -> return dateFormat.format(from) }) }
  • 44. Layout in Java 44 TextField urlField = new TextField(“http://www.google.com”); HBox.setHgrow(urlField, Priority.ALWAYS); HBox hbox = new HBox(); hbox.getChildren().add(urlField); WebView webView = new WebView(); VBox.setVgrow(webView, Priority.ALWAYS); VBox vbox = new VBox(); vbox.getChildren().addAll(hbox, webView);
  • 45. Layout in GroovyFX 45 sg.stage(title: "GroovyFX WebView Demo", show: true) { scene(fill: groovyblue, width: 1024, height: 800) { vbox { hbox(padding: 10, spacing: 5) { textField(“http://www.yahoo.com”, hgrow: "always") button("Go”) } webView(vgrow: "always") } } }
  • 47. Layout in GroovyFX 47 gridPane(hgap: 5, vgap: 10, padding: 25) { columnConstraints(minWidth: 50, halignment: "right") columnConstraints(prefWidth: 250) label("Send Us Your Feedback", font: "24pt sanserif", row: 0, columnSpan: GridPane.REMAINING, halignment: "center", margin: [0, 0, 10]) label("Name: ", row: 1, column: 0) textField(promptText: "Your name", row: 1, column: 1, hgrow: 'always') label("Email:", row: 2, column: 0) textField(promptText: "Your email", row: 2, column: 1, hgrow: 'always') label("Message:", row: 3, column: 0, valignment: "baseline") textArea(row: 3, column: 1, hgrow: "always", vgrow: "always") button("Send Message", row: 4, column: 1, halignment: "right") }
  • 50. And you can do cool stuff like this… https://bitbucket.org/stephanj/tweetwall
  • 51. Conclusion  JavaFX enables graphically rich, fast performing apps  Visually create applications using Scene Builder  Run on Raspberry Pi today!
  • 52. Stephen Chin tweet: @steveonjava blog: http://steveonjava.com nighthacking.com Real Geeks Live Hacking NightHacking Tour
  • 53. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Editor's Notes

  • #2: Feel free to reuse this presentation for your local user groups. Some helpful comments are in the notes section, but feel free to embellish.For more details on JavaFX/Raspberry Pi hacking, check out this post:http://javafx.steveonjava.com/javafx-on-raspberry-pi-3-easy-steps/
  • #3: Java embedded technologies are used in a wide variety of embedded devices. This list is just a small sampling of devices that are currently using Java ME and SE Embedded.
  • #7: The Raspberry Pi is a consumer-focused, low-cost board. It has a slightly slower ARM processor (ARMv6 700Mhz), but a better GPU than the BeagleBoard. Connectivity is via HDMI/Component, USBx2, Ethernet, and Audio out.
  • #10: 14, 15 UART lines so you can get the serial console
  • #12: And getting JavaFX is as simple as downloading Java 7 (it has been bundled since Java 7u4). Also, it is supported across different desktop platforms (shown in the picture).
  • #13: And getting JavaFX is as simple as downloading Java 7 (it has been bundled since Java 7u4). Also, it is supported across different desktop platforms (shown in the picture).
  • #14: And getting JavaFX is as simple as downloading Java 7 (it has been bundled since Java 7u4). Also, it is supported across different desktop platforms (shown in the picture).
  • #51: And do cool stuff with the Pi like this pic of the digital signage for Devoxx, which was running on HDMI monitors at 1920x1080 off of a Raspberry Pi.
  • #52: So in conclusion you can do all this cool stuff! Go buy a Pi and get started with JavaFX today!