scripting with java fx - cédric tabin - december 2007

15

Click here to load reader

Upload: jug-lausanne

Post on 25-May-2015

137 views

Category:

Technology


0 download

DESCRIPTION

Scripting with Java FX - Cédric Tabin - December 2007

TRANSCRIPT

Page 1: Scripting with Java FX - Cédric Tabin - December 2007

Scripting with Java FX

Page 2: Scripting with Java FX - Cédric Tabin - December 2007

Why Java FX?

What is Java FX?

Agenda

The 10 Minute Tutorial

What To Do/Where To Go

Java FX Demo!

Page 3: Scripting with Java FX - Cédric Tabin - December 2007

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 first-class 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/

Page 4: Scripting with Java FX - Cédric Tabin - December 2007

Why Java FX?• Writing GUIs is hard (and annoying)

> Yes, Matisse helps quite a bunch, but...> There are still too many listeners.

Page 5: Scripting with Java FX - Cédric Tabin - December 2007

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

Page 6: Scripting with Java FX - Cédric Tabin - December 2007

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!

Page 7: Scripting with Java FX - Cédric Tabin - December 2007

Java FX: The 10 Minute Tutorialclass HelloWorldModel {

attribute saying: String;}

var model = HelloWorldModel {saying: "Hello Campus"

};

var win = Frame {title: bind "{model.saying} JavaFX"width: 200content: TextField {

value: bind model.saying}visible: true

};

Class definition with single String attribute

Instance of the class called “model” which initializes string

Frame with a single text field. Frame's title and text field's value is bound to model's attribute.

Page 8: Scripting with Java FX - Cédric Tabin - December 2007

Java FX: The 10 Minute Tutorial

import java.lang.StringIndexOutOfBoundsException;

operation substring(s:String, n:Number): String {try {

return s.substring(n);} catch (e:StringIndexOutOfBoundsException) {

throw “sorry, index out of bounds”;}

}

Defining operations (i.e. methods)

Calling Java methods

Can throw any object you like

Page 9: Scripting with Java FX - Cédric Tabin - December 2007

Java FX: The 10 Minute Tutorialvar 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!

Page 10: Scripting with Java FX - Cédric Tabin - December 2007

Java FX: The 10 Minute Tutorial class X {

attribute nums: Number*; } trigger on new X {

insert [3,4] into this.nums;}

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}");}

Object creation trigger

Array insertion trigger

Array replacement trigger

Page 11: Scripting with Java FX - Cédric Tabin - December 2007

Java FX: The 10 Minute Tutorialimport javafx.ui.canvas.*;import javafx.ui.*;

Canvas { content: Group { transform: [rotate(20,0,0)] content: [Rect { x: 20 y: 20 height: 80 width: 300 ... }, Ellipse { cx: 150 cy: 80 ... }, }] }}

Canvas object for arbitrary drawingGroup objects togetherTransform groups

Declarative 2D Graphics

Page 12: Scripting with Java FX - Cédric Tabin - December 2007

demo

Page 13: Scripting with Java FX - Cédric Tabin - December 2007

• 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!

Java FX

What toDo

http://openjfx.dev.java.net

Page 14: Scripting with Java FX - Cédric Tabin - December 2007

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

Page 15: Scripting with Java FX - Cédric Tabin - December 2007

THANK YOU!

Scripting with Java FXhttp://openjfx.dev.java.net