2. About Your Presenter Director SWE, Inovis, Inc. Open-Source JavaFX Hacker MBA Belotti Award UberScrumMaster XP Coach Agile Evangelist WidgetFX JFXtras FEST-JavaFX Piccolo2D Java Champion JavaOneRockstar JUG Leader Pro JavaFX Author 2 Family Man Motorcyclist
3. LearnFX and Win at Devoxx Tweet to answer: @projavafxcourse your-answer-here 3
4. Part 1 - JavaFX Crash Course var x = ['x','o','v','e','d','x']; insert x[5] before x[0]; println("{reverse x[0..<]}"); @projavafxcourse answer
5.
6.
7. Hello Devoxx!: Creating a Stage Stage { title: "Hello Devoxx!" scene: Scene { content: [ "..." ] } } 6 var x = ['x','o','v','e','d','x']; insert x[5] before x[0]; println("{reverse x[0..<]}"); @projavafxcourse answer
8. Hello Devoxx!: Displaying Images ImageView { image: Image { url: "http://www.javoxx.com/download/attachments/1706305/Devoxx09.jpg" } opacity: .5 } 7 var x = ['x','o','v','e','d','x']; insert x[5] before x[0]; println("{reverse x[0..<]}"); @projavafxcourse answer
16. 15 Part 2 - Comparing JavaFX and Java var x = ['x','o','v','e','d','x']; insert x[5] before x[0]; println("{reverse x[0..<]}"); @projavafxcourse answer
17. Language Similarities Java is… Statically typed Compiled to bytecodes Runs on the JVM Has a large library JavaFX is… Statically typed Compiled to bytecodes Runs on the JVM Can call Java libraries 16
19. Integrating JavaFX and Java Calling Java from JavaFX Can call Java interface or classes directly Automatic conversion to and from Arrays and Collections Can even extend Java interfaces and classes Calling JavaFX from Java Easiest way is to create a Java interface that JavaFX extends Can invoke JavaFX as a script and get results back 18
25. Data Binding A variable or a constant can be bound to an expression var x = bind a + b; The bound expression is remembered The dependencies of the expression is watched Variable is updated Regular binding: when dependencies change values Lazy binding: when the variable is accessed var x = bind lazy a+ b; 23
26. What Bind Updates var x = bind if(a) then b else c x is updated if a or b or c changes var x = bind for (i in [a..b]) { i * i } Not everything is recalculated If a = 1 and b = 2, x is [1, 4] If b changes to 3, only the added element is calculated 24 1 4 9
27. Binding to Expressions Binding to a block Bound block may contain any number of defs followed by one expression Dependencies of block is backtraced from the expression Binding to function invocation expression Regular function: dependencies are parameters Bound function: backtraced from final expression inside function 25
28. Binding to Object Literals var a = 3; var b = 4; var p = bind Point { x: a, y: b }; var q = bind Point { x: bind a, y: b }; var r = bind Point { x: bind a, y: bind b }; When a changes: p gets a new instance of Point q and r keep the old instance with a new x value r will never get a new instance of Point (the outer bind in r is useless) 26
29. Binding to Functions Stage { def cModel = CircleModel {}; varsliderRef:Slider; scene: Scene { content: [ Circle { radius: bind cModel.diameter / 2 }, Text { content: bind "Diameter: {%3.0f cModel.diameter}" }, Text { content: bind "Area: {%3.2f cModel.getArea()}" }, sliderRef = Slider { value: bind cModel.diameter with inverse }]}} 27 class CircleModel { vardiameter:Number; bound function getArea():Number { Math.PI * Math.pow(diameter / 2, 2); } } http://learnjavafx.typepad.com/weblog/javafx_app_deployment/
30. JavaFX Sequences Represents collections of homogeneous data A fundamental container data type Rich set of language facilities Contributor to declarative syntax Automatic conversion to and from Java Arrays and Collections 28
31. Creating Sequences Explicit sequence expression [1, 3, 5, 7, 9] Elements are separated by commas Comma may be omitted if element ends with brace 29 1 3 5 7 9
32. Creating Sequences Numeric sequence with range expressions: [1..10] Can have a step: [1..10 step 2] [0.0..0.9 step 0.1] Can be decreasing: [10..1 step -3] Beware of step that goes opposite direction: [10..1] is [] Exclusive right end [1..<5] 30 1 2 3 4 5 6 7 8 9 10 1 3 5 7 9 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 10 7 4 1 1 2 3 4
33. Getting Information from Sequences ints = [1, 3, 5, 7, 9] sizeofintsis 5 ints[0] is 1, ints[1] is 3, ..., ints[4] is 9 ints[-1] is 0 (default value of Integer), so is ints[5] For a sequence of objects, the default is null 31 1 3 5 7 9 [0] [1] [2] [3] [4]
34. Getting Slices From Sequences ints = [1, 3, 5, 7, 9] ints[0..2] is [1, 3, 5] ints[0..<2] is [1, 3] ints[2..] is [5, 7, 9] ints[2..<] is [5, 7] ints[2..0], ints[-2..-1], ints[5..6] are all []s 32 1 3 5 7 9 [0] [1] [2] [3] [4]
35. Getting Subsets from Sequences ints = [1, 3, 5, 7, 9] ints[k | k > 6] is: [7, 9] (k > 6 is a condition) ints[k | indexof k < 2] is: [1, 3] ints[k | k > 10] is: [] 33 1 3 5 7 9 [0] [1] [2] [3] [4]
38. Sequence Puzzlers FX What is the size of this sequence: [1..10 step -1] What does this evaluate to: [10..<20 step 2][k|k>17] What is the size of this sequence: sizeof [20..1 step -3] 36 1 A: 0 2 A: [18] 3 A: 1
48. JavaFX Mobile Advantages Write Once, Run Anywhere Desktop, Mobile, Set-top Boxes (future) Large Embedded Base Built on top of Java ME platform Wide Range of Devices Runs on Feature Phones, Smart Phones Currently available for Windows Mobile devices
49. JavaFX Mobile Constraints Screen Size Your application has to be capable of adapting to different screen sizes as small as 320 by 240. Common Profile Mobile applications are limited to the JavaFX APIs that are part of the Common Profile, which is a subset of the Desktop Profile. Performance Mobile applications run on much less powerful devices, so they have less CPU and memory resources available to work with.
51. Changes to Improve Hello Devoxx! It runs as is with no changes, but was not designed for the mobile format. We can do better: Replace all hard-coded sizes with a bind Scale the background image to the screen size Put an error up on network failure The improved version also works on the desktop. 49
68. Sphere Challenge 66 Andres Almiray’s Weblog http://www.jroller.com/aalmiray/entry/griffon_gfxbuilder_fxbuilder_side_by “The following snapshot shows a couple of spheres drawn with GfxBuilder and FxBuilder, can you guess which one is which? … This is by no means a post to bash JavaFX rather to point out some of its deficiencies” -- Andres Almiray (taken completely out of context)
69. Sphere Challenge – JavaFX Response Composition: RadialGradient for the Sphere Three additional RadialGradients for the light sources A blurred shadow underneath Features: All Bound/Relative Coordinates Configurable – Base, Ambient, Specular, Shine Colors Shadow Size and Height Uses New JFXtrasColorUtil Library JavaFX Caching for High Performance 67 Will be shipped with JFXtras 0.6
78. Load the Media var source = "http://projavafx.com/movies/ elephants-dream-640x352.flv"; var player = bind SimpleMoviePlayer { media: Media { source: source } width: bind widget.width height: bind widget.height } 76
85. WidgetFX Contest Results! 3rd Place Infix WeatherWidget Larry Dickson 2nd Place RadioFX Yannick Van Godtsenhoven 1st Place ScreenshotFX Pär Dahlberg 83
86. JavaFXpert RIA Exemplar Challenge "Create an application in JavaFX that exemplifies the appearance and behavior of a next-generation enterprise RIA (rich internet application)". Grand Prize: $2,000 USD (split between a two-man graphics artist and application developer team) Deadline: 10 January, 2010 For more info: http://learnjavafx.typepad.com/ 84
90. 88 Thank You Stephen Chin http://steveonjava.com/ Tweet: steveonjava Thanks to my co-authors, Jim, Weiqi , and Dean for content included in this talk!