Color |
JavaFX Script | ruby |
Rectangle { fill: Color.BLACK } |
Rectangle { fill: Color.rgb(255,204,0) } |
Rectangle { fill: Color.web("#ff0066") } |
Rectangle { stroke: Color.BLACK } |
Shape |
JavaFX Script | ruby |
Line { startX: 30 startY: 20 endX: 30 endY: 20 } |
Rectangle { x: 10 y: 20 width: 30 height: 30
fill: Color.WHITE stroke: Color.BLACK
} |
Path {
stoke: Color.BLACK
MoveTo
LineTo
LineTo
LineTo
} |
Variables and Datatypes |
JavaFX Script | ruby |
var x = 70;//initialize
x = 30; |
var x = 70.0; |
var a = [5,6,7]; //initialize
a[0] = 12; //reassign |
var a = [5,6,7]; //initialize
insert 12 into a; //append |
Loops and Conditionals |
JavaFX Script | ruby |
while(true) {
// do stuff
} |
for(i in [0..10]) {
// do stuff
} |
//loop over a sequence
for(i in a) {
// do stuff
} |
if(c == 1) {
// do stuff
} |
if(c != 1) {
// do stuff
} |
if(c < 1) {
// do stuff
} |
if(c < 1 and c > 1) {
// do stuff
} |
if(c != 1) {
// do stuff
} else if (d != 1) {
// do other stuff
} else {
// do last stuff
} |
Structure |
JavaFX Script | ruby |
//comment |
/* comment */ |
public function doStuff(x:Number):Void {
// do stuff
}
doStuff(12); |
public function doStuff(x:Number):Number {
// do stuff
// return num;
}
x = doStuff(12); |
Input |
JavaFX Script | ruby |
Rectangle {
onMousePressed: function(e:MouseEvent) {
x = e.getX();
}
onMouseDragged: function(e:MouseEvent) {
x = e.getX();
}
}
|
Rectangle {
onKeyPressed: function(e:KeyEvent) {
var key = e.getKeyChar();
}
} |
Animation |
JavaFX Script | ruby |
var rect = Rectangle { }
var anim = Timeline {
keyFrames: [
at(0s) { rect.x => 100},
at(1s) { rect.x => 200},
]
repeatCount: Timeline.INDEFINITE
toggle: true
}; |
Binding and Triggers |
JavaFX Script | ruby |
var foo = 0.0;
var bar = bind foo;
foo = 2.2; // bar is updated
|
// create a class with a trigger
public class Foo {
public attribute bar:Number = 0.0 on replace {
System.out.println("bar was changed to {bar}");
}
}
|
Packages and Import Statements |
JavaFX Script | ruby |
package org.myname.myapp; |
import java.lang.System; |
Class Definition |
JavaFX Script | ruby |
//declare a class
public class Foo extends CustomNode {
// attributes and functions go here
} |
//declare an attribute
public class Foo extends CustomNode {
public attribute bar:Number = 1.0;
} |
//declare a function
public class Foo extends CustomNode {
public function baz(a:Number, b:String):Number {
return a*2;
}
} |
Audio and Video |
JavaFX Script | ruby |
// Create a video player
import javafx.scene.media.*;
MediaView {
mediaPlayer: MediaPlayer {
media: Media { source: "file://myvideo.mov" }
}
} |
// Create an audio player
import javafx.scene.media.*;
MediaView {
mediaPlayer: MediaPlayer {
media: Media { source: "file://myvideo.mp3" }
}
} |