2. Agenda
What is Java FX?
Why Java FX?
The 10 Minute Tutorial
Java FX Demo!
What To Do/Where To Go
3. Introduction: What is Java FX?
“JavaFX Script is a highly productive scripting language that
enables content developers to create rich media and content
for deployment on Java environments. JavaFX Script is a
declarative, statically-typed programming language. It has firstclass functions, declarative syntax, list-comprehensions, and
incremental dependency-based evaluation. It can make direct
calls to Java APIs that are on the platform.”
--https://openjfx.dev.java.net/
4. Why Java FX?
• Writing GUIs is hard (and annoying)
> Yes, Matisse helps quite a bunch, but...
> There are still too many listeners.
5. Why Java FX?
• Writing GUIs is hard (and annoying)
> Yes, Matisse helps quite a bunch, but...
> There are still too many listeners.
• GUIs by default are ugly
> A hierarchy of rectangular “grey boxes” (not limited to Java!)
> Not as snazzy as Flash websites
6. Why Java FX?
• Writing GUIs is hard (and annoying)
> Yes, Matisse helps quite a bunch, but...
> There are still too many listeners.
• GUIs by default are ugly
> A hierarchy of rectangular “grey boxes” (not limited to Java!)
> Not as snazzy as Flash websites
• Java 2D provides much what is needed, but...
> It is rather difficult to use for this purpose
> It does not have “compositional” behavior
Java FX's declarative syntax, combining Swing-like user-interface
widgets with compositional, Java 2D-like functionality makes writing
flashy graphical user interfaces easy!
7. Java FX: The 10 Minute Tutorial
class HelloWorldModel {
attribute saying: String;
}
Class definition with
single String attribute
var model = HelloWorldModel {
saying: "Hello Campus"
};
Instance of the class
called “model” which
initializes string
var win = Frame {
title: bind "{model.saying} JavaFX"
width: 200
content: TextField {
value: bind model.saying
}
visible: true
};
Frame with a single
text field. Frame's title
and text field's value is
bound to model's
attribute.
8. Java FX: The 10 Minute Tutorial
import java.lang.StringIndexOutOfBoundsException;
Defining
operation substring(s:String, n:Number): String { operations (i.e.
try {
methods)
return s.substring(n);
} catch (e:StringIndexOutOfBoundsException) {
throw “sorry, index out of bounds”;
}
}
Calling Java methods
Can throw any object
you like
9. Java FX: The 10 Minute Tutorial
var x = [1,2,3];
insert 10 into x;
insert 12 before x[1];
delete x[. == 12];
delete x[. >= 3];
insert 5 after x[. == 1];
insert 13 as first into x;
delete x;
Array Initialization
yields [1, 2, 3, 10]
yields [1, 12, 2, 3, 10]
yields [1, 2, 3, 10]
yields [1, 2]
yields [1, 5, 2]
yields [13, 1, 5, 2]
yields []
function factors(n) {
return select i from i in [1..n/2] where n % i == 0;
}
Database-like Queries
for Arrays!
10. Java FX: The 10 Minute Tutorial
class X {
attribute nums: Number*;
}
trigger on new X {
insert [3,4] into this.nums;
}
Object creation trigger
Array insertion trigger
Array replacement
trigger
trigger on insert num into X.nums {
System.out.println("just inserted {num} into X.nums at
position {indexof num}");
}
trigger on X.num[oldValue] = newValue {
System.out.println("X.num: just replaced {oldValue} with
{newValue}");
}
11. Java FX: The 10 Minute Tutorial
import javafx.ui.canvas.*;
import javafx.ui.*;
Canvas object for
arbitrary drawing
Canvas {
content: Group {
transform: [rotate(20,0,0)]
content:
[Rect {
x: 20
y: 20
height: 80
width: 300
...
},
Ellipse {
cx: 150
cy: 80
...
},
}]
}
}
Group objects together
Transform groups
Declarative 2D
Graphics
13. Java FX
What to
Do
• Download Java FX & IDE
Plugins for Netbeans or
Eclipse
• Join OpenJFX Java.net
Project
• Do Java FX Tutorials
• Participate on Java FX
Forums
• Create something cool!
http://openjfx.dev.java.net
14. Java FX Resources
• Java FX Project Site: http://openjfx.dev.java.net
> Java.net: Download early versions of Java FX
> IDE Plugins, Tutorials, Forums, FAQs
> “Getting Started With the JavaFX Script Language”
> “JavaFX Script 2D Graphics Tutorial”
> “The JavaFX Script Programming Language Reference”
• Planet FX Wiki: http://jfx.wikia.com/wiki/Main_Page
> Open-source documentation site for Java FX
• Chris Oliver's Blog: http://blogs.sun.com/chrisoliver/
> Latest news, other informal information
> Source code for lots of demos (Space Invaders, Calculator)
• Sun's Java FX Site:
http://www.sun.com/software/javafx/
> Sun Microsystems official product page