SlideShare une entreprise Scribd logo
1  sur  80
JavaFX - Rich GUIs Made Easy Carol McDonald Technology Evangelist
Agenda ,[object Object]
Advanced features ,[object Object]
User Input
Animation
Media
Work with Restful Web Services ,[object Object]
Summary and References
Overview of the  JavaFX SDK
JavaFX Vision * ,[object Object]
Multiple devices JavaFX is  THE  platform for  creating and delivering  Rich Internet Application s  across all the screens of your life
Targeting Developer/Designer Workflow ,[object Object],Sean Wani (Graphic Designer)‏ Karl May (Mashup author/builder)‏ Amy Lewis (Suburban wife/mom)‏ Tom Hammer (Media Editor)‏ Saloni Sarin (Creative Director)‏ Livleen (Student)‏ Samir Arora (Business Professional)‏ Adam Nielson (Web Master)‏ Wayne Stidolph (Programmer)‏ Rich Internet Apps + content Across desktop,  mobile, TV, car Creative Community Consumers
Things You Can Build with JavaFX
Simple Video Player ,[object Object]
3-D Display Shelf With the PerspectiveTransform ,[object Object]
Demo: JavaFX Sample Apps from javafx.com
JavaFX Script ,[object Object]
Everything in JavaFX script is an expression
All blocks are expressions
The last line is the result  println(“ Hello World ”) The result of the println expression is null
JavaFX Script Programming Language  ,[object Object]
Facilitates rapid GUI development
Integrates with and Leverages Java Platform
Runs on Java™ Virtual Machine ,[object Object]
Example of JavaFX Application   Stage {  title: "circle" width: 240 height: 200 scene : { content : [ Circle {  centerX: 50 centerY: 50 radius: 50 fill: Color.RED } ] } } Stage Scene content Circle Stage class defines the container window, size and title  Scene class defines the content to be displayed in the window
Example of JavaFX Application import javafx.scene.Scene; import javafx.scene.shape.Circle; import javafx.stage.Stage; Stage { scene: { content: [ Circle {  centerX: 50 centerY: 50 radius: 50 fill: Color.RED } ] } }
Demo: http://www.javapassion.com/handsonlabs/javafx_lang/#Exercise_1
JavaFX Technology Stack Java2D java.awt.* SceneGraph com.sun.scenario.scenegraph.* com.sun.scenario.animation.* com.sun.scenario.effects.* JavaFX Script Programming Language javafx.gui.* javafx.gui.effect.*  javafx.animation.*  Java APIs script Swing javax.swing.* Note: JavaFX Script programs can call any Java APIs
(Some) Language Features
Declarations ,[object Object]
Constants  var fred:Number; def PI:Number = 22 / 7; Data Types ,[object Object],[object Object]
var i = 10; ,[object Object],[object Object]
Number / Integer  – byte, short, int, long, BigInteger
Boolean
Void
Data Types ,[object Object],A function can be a variable var doExit = function():Void { System.exit(0); }; doExit();  //executed when invoked Functions
Declaring Classes // This class extends a Java interface public class FooModel extends TableModel { ... } // This class defines two variables and a function public class Location { public var x:Number; public var y:Number; public function move(newX:Number, newY:Number):Void { x = newX; y = newY; } }
Basic JavaFXScript Class class HelloWorldNode  extends  CustomNode { public  var  text:String; public  override  function  create() : Node { return Text { x: 10 ,  y: 50 font: Font { size: 50 } content: bind text } }; } Syntax is Java-like with shades of JavaScript
Object Literal class Point {  var x : Integer;  var y : Integer;  function show() { println("Point {x}, {y}") }  } //instance of object literal var myPoint = Point {x: 12,  y: 9} def yourPoint = Point {x: 22,  y: 19} myPoint.show() ,[object Object]
Similar to JavaScript
variable: initial-value
Sequences ,[object Object],var time:Duration []  = [60ms, 60s, 60m, 60h]; var days = [ 1..31 ]; insert  5s  into  time; delete  31  from  days; A Sequence represents an ordered list of objects
Data Binding ,[object Object],var  h  = 10; var  w  = 2; //Whenever  h  or  w  changes,  area  updated var  area  =  bind   h * w ; println( area );  //prints 20 w =3; println( area );  //prints 30 Eliminates the listener pattern Useful for binding Model to View
Triggers ,[object Object]
When the value of the  variable changes , the  code is executed
Similar to  PropertyChangeListener //oldValue is optional var  text   on replace  oldValue  { println(“Old value = '{oldValue}'”); println(“New value = '{text}'”); } text  = “Hello” //prints  Old value = '' //prints  New value = 'Hello'
Graphical Objects *   * The fun stuff
JavaFX Stage Scene  Stage  is the  top level container window Scene  is a drawing surface  container that holds the scene graph nodes. content   holds JavaFX graphical elements which define the graphical content of the application.
JavaFX Scene Graph Programming Model (cont.) top level container window container that holds the scene graph nodes
What is a Scene Graph? ,[object Object]
Basis of JavaFX graphics engine ,[object Object],[object Object],[object Object],[object Object]
Events – mouse, keyboard, node updates
Animation – varying properties over time
Group – Node Container  Group { transforms: Translate { x:15, y, 15 } content: [ Text { x: 10, y: 50 font: Font: { size: 50 } content: “Hello World” } Circle { centerX: 100, centerY: 100 radius: 40 fill: Color.BLACK } ] } Group Circle Text x:15 y:15
JavaFX Architecture  Models a JavaFX application Java 2D Effects Project Scene Graph
Base Graphical Objects ,[object Object]
Clip – displaying only part of the node based on a geometric shape
Effect – type of effect, eg. blurring, shadowing, to apply
Events – mouse, keyboard
Opacity – setting the translucency
List is not exhaustive
Text ,[object Object],Text { effect: DropShadow { offsetX: -10 offsetY: -10 } font: Font { name: “DirtyBakersDozen” size: 50 } fill: Color.ROYALBLUE stroke: Color.BLUE, strokeWidth: 3 x: 15, y: 80 content: "Hello World" }
Geometric Shapes ,[object Object]
Very similar to text Circle { centerX: 70, centerY: 70 radius: 50 fill: Color.PINK stroke: Color.RED strokeWidth: 3 strokeDashArray: [ 7 ] strokeDashOffset: 2 }
Custom Shapes ,[object Object]
Drawing a totally new shape ,[object Object],[object Object]
Example – ShapeIntersect  var  rectangle  =  Rectangle  { x:10 y:20 width:140 height:70  fill:Color.LIGHTBLUE stroke:Color.BLUE arcHeight:20 arcWidth:20 strokeWidth:3} var  diamond  =  Polygon   { points:[90,90, 110,70, 130,90, 110,110 ]  fill:Color.LIGHTPINK  stroke:Color.RED strokeWidth: 3} var  newShape  =  ShapeIntersect  { translateX:170 fill: Color.LIGHTGREEN stroke: Color.GREEN strokeWidth: 3 //Union of the 2 shapes a: [ rectangle  diamond  ] }
Custom Shapes ,[object Object]
Drawing a totally new shape ,[object Object],[object Object],[object Object]
Example – Path Path { fill: Color.LIGHTGRAY stroke: Color.GRAY strokeWidth: 3 elements: [ MoveTo { x: 15 y: 15 }, ArcTo { x: 50 y: 10 radiusX: 20    radiusY: 20 sweepFlag: true}, ArcTo { x: 70 y: 20 radiusX: 20  radiusY: 20 sweepFlag: true}, ArcTo { x: 50 y: 60 radiusX: 20  radiusY: 20 sweepFlag: true}, ArcTo { x: 20 y: 50 radiusX: 10  radiusY: 5 sweepFlag:  false }, ArcTo { x: 15 y: 15 radiusX: 10  radiusY: 10 sweepFlag: true}, ] effect: Lighting{light: DistantLight{azimuth: 90}} }
Images ,[object Object]
Image represents an in memory Image ,[object Object]
Fit within a specific width/height
When fit on Image level, keeps smaller image in memory myImageView = ImageView { image: Image { url: "file:///..."} }
Images ImageView = ImageView { clip: Rectangle { y: 30 x: 50 width: 350 height: 100 } image: Image { url: "file:///..."} }
JavaFX Catalog client
JavaFX Stage Scene   // Application User Interface var stageContent: Node[]; stageContent = [bgImage,  nextButton, backButton,  titleText,  thumbImageViewGroup,  fullImageView ]; def  stage  =  Stage  { title: "Pet Catalog" width: 201 height: 201 scene : Scene { content : Group { content: bind stageContent } fill: Color.TRANSPARENT } }
JavaFX Stage Scene  var stageContent: Node[]; stageContent  = [bgImage,  nextButton, backButton,  titleText,  thumbImageViewGroup,  fullImageView ]; def  stage  =  Stage  { title: "Pet Catalog" width: 201 height: 201 scene : Scene { content : Group { content: bind  stageContent } fill: Color.TRANSPARENT } }
Effects  ,[object Object]
Many standard built in ,[object Object]

Contenu connexe

Similaire à Java Fx Overview Tech Tour

Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFXTom Mix Petreca
 
JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]Stephen Chin
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderAndres Almiray
 
Scripting with Java FX - Cédric Tabin - December 2007
Scripting with Java FX - Cédric Tabin - December 2007Scripting with Java FX - Cédric Tabin - December 2007
Scripting with Java FX - Cédric Tabin - December 2007JUG Lausanne
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not FlashThomas Fuchs
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptxmadan r
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1Bitla Software
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideStephen Chin
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suiteScott Ackerman
 
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8Shaymaa
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFXFulvio Corno
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFXFulvio Corno
 
JavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesJavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesStephen Chin
 

Similaire à Java Fx Overview Tech Tour (20)

Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFX
 
JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]JavaFX 2.0 With Alternative Languages [Portuguese]
JavaFX 2.0 With Alternative Languages [Portuguese]
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
 
Scripting with Java FX - Cédric Tabin - December 2007
Scripting with Java FX - Cédric Tabin - December 2007Scripting with Java FX - Cédric Tabin - December 2007
Scripting with Java FX - Cédric Tabin - December 2007
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
JavaFX introduction
JavaFX introductionJavaFX introduction
JavaFX introduction
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suite
 
Plunge into HTML5 Canvas – Let’s begin
Plunge into HTML5 Canvas – Let’s beginPlunge into HTML5 Canvas – Let’s begin
Plunge into HTML5 Canvas – Let’s begin
 
JavaFX
JavaFXJavaFX
JavaFX
 
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8HTML5: The Future of Web Development with IE9, IE10 and Windows 8
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
 
Programming with JavaFX
Programming with JavaFXProgramming with JavaFX
Programming with JavaFX
 
JavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative LanguagesJavaFX 2.0 and Alternative Languages
JavaFX 2.0 and Alternative Languages
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 

Plus de Carol McDonald

Introduction to machine learning with GPUs
Introduction to machine learning with GPUsIntroduction to machine learning with GPUs
Introduction to machine learning with GPUsCarol McDonald
 
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...Carol McDonald
 
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DBAnalyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DBCarol McDonald
 
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...Carol McDonald
 
Predicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningPredicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningCarol McDonald
 
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DBStructured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DBCarol McDonald
 
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...Carol McDonald
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...Carol McDonald
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...Carol McDonald
 
How Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health CareHow Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health CareCarol McDonald
 
Demystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep LearningDemystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep LearningCarol McDonald
 
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...Carol McDonald
 
Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures Carol McDonald
 
Spark machine learning predicting customer churn
Spark machine learning predicting customer churnSpark machine learning predicting customer churn
Spark machine learning predicting customer churnCarol McDonald
 
Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1Carol McDonald
 
Applying Machine Learning to Live Patient Data
Applying Machine Learning to  Live Patient DataApplying Machine Learning to  Live Patient Data
Applying Machine Learning to Live Patient DataCarol McDonald
 
Streaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka APIStreaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka APICarol McDonald
 
Apache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision TreesApache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision TreesCarol McDonald
 
Advanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming DataAdvanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming DataCarol McDonald
 

Plus de Carol McDonald (20)

Introduction to machine learning with GPUs
Introduction to machine learning with GPUsIntroduction to machine learning with GPUs
Introduction to machine learning with GPUs
 
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
Streaming healthcare Data pipeline using Apache APIs: Kafka and Spark with Ma...
 
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DBAnalyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
Analyzing Flight Delays with Apache Spark, DataFrames, GraphFrames, and MapR-DB
 
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...Analysis of Popular Uber Locations using Apache APIs:  Spark Machine Learning...
Analysis of Popular Uber Locations using Apache APIs: Spark Machine Learning...
 
Predicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine LearningPredicting Flight Delays with Spark Machine Learning
Predicting Flight Delays with Spark Machine Learning
 
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DBStructured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
Structured Streaming Data Pipeline Using Kafka, Spark, and MapR-DB
 
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
Streaming Machine learning Distributed Pipeline for Real-Time Uber Data Using...
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real-Ti...
 
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
Applying Machine Learning to IOT: End to End Distributed Pipeline for Real- T...
 
How Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health CareHow Big Data is Reducing Costs and Improving Outcomes in Health Care
How Big Data is Reducing Costs and Improving Outcomes in Health Care
 
Demystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep LearningDemystifying AI, Machine Learning and Deep Learning
Demystifying AI, Machine Learning and Deep Learning
 
Spark graphx
Spark graphxSpark graphx
Spark graphx
 
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
Applying Machine learning to IOT: End to End Distributed Distributed Pipeline...
 
Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures Streaming patterns revolutionary architectures
Streaming patterns revolutionary architectures
 
Spark machine learning predicting customer churn
Spark machine learning predicting customer churnSpark machine learning predicting customer churn
Spark machine learning predicting customer churn
 
Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1Fast Cars, Big Data How Streaming can help Formula 1
Fast Cars, Big Data How Streaming can help Formula 1
 
Applying Machine Learning to Live Patient Data
Applying Machine Learning to  Live Patient DataApplying Machine Learning to  Live Patient Data
Applying Machine Learning to Live Patient Data
 
Streaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka APIStreaming Patterns Revolutionary Architectures with the Kafka API
Streaming Patterns Revolutionary Architectures with the Kafka API
 
Apache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision TreesApache Spark Machine Learning Decision Trees
Apache Spark Machine Learning Decision Trees
 
Advanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming DataAdvanced Threat Detection on Streaming Data
Advanced Threat Detection on Streaming Data
 

Java Fx Overview Tech Tour

  • 1. JavaFX - Rich GUIs Made Easy Carol McDonald Technology Evangelist
  • 2.
  • 3.
  • 7.
  • 9. Overview of the JavaFX SDK
  • 10.
  • 11. Multiple devices JavaFX is THE platform for creating and delivering Rich Internet Application s across all the screens of your life
  • 12.
  • 13. Things You Can Build with JavaFX
  • 14.
  • 15.
  • 16. Demo: JavaFX Sample Apps from javafx.com
  • 17.
  • 18. Everything in JavaFX script is an expression
  • 19. All blocks are expressions
  • 20. The last line is the result println(“ Hello World ”) The result of the println expression is null
  • 21.
  • 22. Facilitates rapid GUI development
  • 23. Integrates with and Leverages Java Platform
  • 24.
  • 25. Example of JavaFX Application Stage { title: "circle" width: 240 height: 200 scene : { content : [ Circle { centerX: 50 centerY: 50 radius: 50 fill: Color.RED } ] } } Stage Scene content Circle Stage class defines the container window, size and title Scene class defines the content to be displayed in the window
  • 26. Example of JavaFX Application import javafx.scene.Scene; import javafx.scene.shape.Circle; import javafx.stage.Stage; Stage { scene: { content: [ Circle { centerX: 50 centerY: 50 radius: 50 fill: Color.RED } ] } }
  • 28. JavaFX Technology Stack Java2D java.awt.* SceneGraph com.sun.scenario.scenegraph.* com.sun.scenario.animation.* com.sun.scenario.effects.* JavaFX Script Programming Language javafx.gui.* javafx.gui.effect.* javafx.animation.* Java APIs script Swing javax.swing.* Note: JavaFX Script programs can call any Java APIs
  • 30.
  • 31.
  • 32.
  • 33. Number / Integer – byte, short, int, long, BigInteger
  • 35. Void
  • 36.
  • 37. Declaring Classes // This class extends a Java interface public class FooModel extends TableModel { ... } // This class defines two variables and a function public class Location { public var x:Number; public var y:Number; public function move(newX:Number, newY:Number):Void { x = newX; y = newY; } }
  • 38. Basic JavaFXScript Class class HelloWorldNode extends CustomNode { public var text:String; public override function create() : Node { return Text { x: 10 , y: 50 font: Font { size: 50 } content: bind text } }; } Syntax is Java-like with shades of JavaScript
  • 39.
  • 42.
  • 43.
  • 44.
  • 45. When the value of the variable changes , the code is executed
  • 46. Similar to PropertyChangeListener //oldValue is optional var text on replace oldValue { println(“Old value = '{oldValue}'”); println(“New value = '{text}'”); } text = “Hello” //prints Old value = '' //prints New value = 'Hello'
  • 47. Graphical Objects * * The fun stuff
  • 48. JavaFX Stage Scene Stage is the top level container window Scene is a drawing surface container that holds the scene graph nodes. content holds JavaFX graphical elements which define the graphical content of the application.
  • 49. JavaFX Scene Graph Programming Model (cont.) top level container window container that holds the scene graph nodes
  • 50.
  • 51.
  • 52. Events – mouse, keyboard, node updates
  • 53. Animation – varying properties over time
  • 54. Group – Node Container Group { transforms: Translate { x:15, y, 15 } content: [ Text { x: 10, y: 50 font: Font: { size: 50 } content: “Hello World” } Circle { centerX: 100, centerY: 100 radius: 40 fill: Color.BLACK } ] } Group Circle Text x:15 y:15
  • 55. JavaFX Architecture Models a JavaFX application Java 2D Effects Project Scene Graph
  • 56.
  • 57. Clip – displaying only part of the node based on a geometric shape
  • 58. Effect – type of effect, eg. blurring, shadowing, to apply
  • 59. Events – mouse, keyboard
  • 60. Opacity – setting the translucency
  • 61. List is not exhaustive
  • 62.
  • 63.
  • 64. Very similar to text Circle { centerX: 70, centerY: 70 radius: 50 fill: Color.PINK stroke: Color.RED strokeWidth: 3 strokeDashArray: [ 7 ] strokeDashOffset: 2 }
  • 65.
  • 66.
  • 67. Example – ShapeIntersect var rectangle = Rectangle { x:10 y:20 width:140 height:70 fill:Color.LIGHTBLUE stroke:Color.BLUE arcHeight:20 arcWidth:20 strokeWidth:3} var diamond = Polygon { points:[90,90, 110,70, 130,90, 110,110 ] fill:Color.LIGHTPINK stroke:Color.RED strokeWidth: 3} var newShape = ShapeIntersect { translateX:170 fill: Color.LIGHTGREEN stroke: Color.GREEN strokeWidth: 3 //Union of the 2 shapes a: [ rectangle diamond ] }
  • 68.
  • 69.
  • 70. Example – Path Path { fill: Color.LIGHTGRAY stroke: Color.GRAY strokeWidth: 3 elements: [ MoveTo { x: 15 y: 15 }, ArcTo { x: 50 y: 10 radiusX: 20 radiusY: 20 sweepFlag: true}, ArcTo { x: 70 y: 20 radiusX: 20 radiusY: 20 sweepFlag: true}, ArcTo { x: 50 y: 60 radiusX: 20 radiusY: 20 sweepFlag: true}, ArcTo { x: 20 y: 50 radiusX: 10 radiusY: 5 sweepFlag: false }, ArcTo { x: 15 y: 15 radiusX: 10 radiusY: 10 sweepFlag: true}, ] effect: Lighting{light: DistantLight{azimuth: 90}} }
  • 71.
  • 72.
  • 73. Fit within a specific width/height
  • 74. When fit on Image level, keeps smaller image in memory myImageView = ImageView { image: Image { url: "file:///..."} }
  • 75. Images ImageView = ImageView { clip: Rectangle { y: 30 x: 50 width: 350 height: 100 } image: Image { url: "file:///..."} }
  • 77. JavaFX Stage Scene // Application User Interface var stageContent: Node[]; stageContent = [bgImage, nextButton, backButton, titleText, thumbImageViewGroup, fullImageView ]; def stage = Stage { title: "Pet Catalog" width: 201 height: 201 scene : Scene { content : Group { content: bind stageContent } fill: Color.TRANSPARENT } }
  • 78. JavaFX Stage Scene var stageContent: Node[]; stageContent = [bgImage, nextButton, backButton, titleText, thumbImageViewGroup, fullImageView ]; def stage = Stage { title: "Pet Catalog" width: 201 height: 201 scene : Scene { content : Group { content: bind stageContent } fill: Color.TRANSPARENT } }
  • 79.
  • 80.
  • 83. Glow
  • 86. Example: DropShadow Text { effect: DropShadow { offsetY: 3 color: Color.GREEN radius: 20.0 }; ... }, Circle { effect: DropShadow { offsetX: 10 offsetY: 20 color: Color.BLUE radius: 30.0 } ... }
  • 87. Some Effects Supported In JavaFX effect: SepiaTone { level: 0.5 } effect: Glow { level: 0.7 } effect: GaussianBlur { input: SepiaTone { level: 0.5 } radius: 10.0 } effect: Reflection { fraction: 0.7 } Original image
  • 88. Lighting Effect effect: Lighting{ surfaceScale: 7 light: DistantLight{ azimuth: 90 elevation: 30 } } effect: Lighting{ surfaceScale: 7 light: SpotLight { x: 0 y :0 z: 50 pointsAtX: 10 pointsAtY: 10 pointsAtZ: 0 color: Color.YELLOW } }
  • 89. Demo: DropShadow, http://www.javapassion.com/handsonlabs/javafx_guibasics/index.html#7.1 DropShadow with Binding, http://www.javapassion.com/handsonlabs/javafx_customnode/index.html EffectsPlayground http://javafx.com/samples/EffectsPlayground/index.html
  • 91.
  • 92. Example – Handling Events var rectangle:Rectangle = Rectangle { x: 20, y: 10 width: 150, height: 70 arcWidth: 50, arcHeight: 50 fill : Color.LIGHTBLUE stroke: Color.ROYALBLUE strokeWidth: 3 onMouseEntered : function( e: MouseEvent ):Void { rectangle. fill = Color.WHITESMOKE; } onMouseExited : function( e: MouseEvent ):Void { rectangle.fill = Color.LIGHTBLUE; } } Changing the color of the rectangle
  • 93. Example – Handling Events var sx:Number = 0; var dx:Number = 0; var sy:Number = 0; var dy:Number = 0; var rectangle:Rectangle = Rectangle { x: bind dx y: bind dy width: 150 height: 70 arcWidth: 50, arcHeight: 50 fill: Color.LIGHTBLUE stroke: Color.ROYALBLUE strokeWidth: 3 cursor : Cursor.HAND onMousePressed : function( e: MouseEvent ) :Void { sx = e.dragX - dx; sy = e.dragY - dy; } onMouseDragged : function( e: MouseEvent ) :Void { dx = e.dragX - sx; dy = e.dragY - sy; } } Dragging an object around the screen
  • 94. Demo: Simple Sketch gui2_interaction_Sketch_basic_3steps http://www.javapassion.com/handsonlabs/javafx_guibasics2/#1.3
  • 95.
  • 96.
  • 97.
  • 98. Need to specify the node to perform the transition on
  • 99.
  • 100. FadeTransition – opacity
  • 101. TranslateTransition – move a node along a straight line
  • 102. PathTransition – move an object along a defined path
  • 103. ScaleTranstion – grows or shrinks a node
  • 104. RotationTransition var rNode = Rectangle {....} var rotTransition = RotateTransition { duration: 3s node: rNode byAngle: 180 repeatCount:4 autoReverse: true } var princess:ImageView = ImageView { image: Image { url: "{__DIR__}princess.png" } onMouseClicked: function( e: MouseEvent ):Void { rotTransition.play(); } }
  • 105. Demo: Transitions http://www.javapassion.com/handsonlabs/javafx_animation/#Exercise_1 http://www.javapassion.com/handsonlabs/javafx_animation/#Exercise_2
  • 106.
  • 107.
  • 108.
  • 109. Demo: simple animation http://www.javapassion.com/handsonlabs/javafx_animation/
  • 110. Example – expanding Circle var cRadius; var circle: Circle = Circle { centerX: 300, centerY: 300 radius: bind cRadius fill: Color.LIGHTBLUE onMousePressed: function( e: MouseEvent ):Void { tRadius.playFromStart(); } } Stage { scene: Scene { content: [circle] } }
  • 111. Example – Defining Key Frames var tRadius : Timeline = Timeline { keyFrames: [ KeyFrame { //start point time: 0s values: [ cRadius => 30 ] } KeyFrame { //end point time: 5s values: [ cRadius => 300 tween Inter polator.LINEAR ] } ] } movement from the beginning to the end states Interpolator calculates the states that occur between animation frames 0s 1s 2s 3s 4s 5s 6s Key value radius = 30 radius = 300 Keyframes How the value changes over time
  • 112. at() (Shorthand notation) keyFrames: [ at(0ms) { cRadius => 30 } at(500ms) { cRadius => 300 tween Interpolate.LINEAR } ] var tRadius = Timeline { keyFrames: [ KeyFrame { time: 0ms values: [cRadius => 30 ] }, KeyFrame { time: 500ms values: [ cRadius => 300 tween Interpolator.LINEAR ] } ] };
  • 113. Example – expanding Circle var cRadius:Number = 30; var tRadius :Timeline = Timeline { keyFrames: [ at(3s) { cRadius => 200 tween Interpolator.LINEAR} ] }; var circle: Circle = Circle { centerX: 300, centerY: 300 radius: bind cRadius fill: Color.LIGHTBLUE onMousePressed: function( e: MouseEvent ):Void { tRadius.playFromStart(); } }
  • 114. Example – Animating an Object var x : Number=0; Timeline { keyFrames: [ at (7s) { x => 387.0 tween Interpolator.LINEAR} ] }.play(); Path{ ... translateX: bind x ...}
  • 115. Demo: Building “Picture Display” Step by Step http://www.javapassion.com/handsonlabs/javafx_customnode/index.html
  • 116. Work with Restful Web Services
  • 117. RESTful Catalog Service JavaFX client JAX-RS, JAXB, JPA DB Registration Application JAX-RS class JavaFX client JAXB class Entity Class ItemsConverter Item ItemsResource
  • 119. RESTful Pet Catalog Web Service http://petstore/catalog/resources/items/ HTTP GET Response XML items <item> <imageurl>http://host/catalog/images/anthony.jpg</imageurl> <name>Friendly Cat</name> <price>307.10</price> <productid>feline01</productid> </item> Server Client Addressable Resources Web Container
  • 120.
  • 121. Need to specify the location and the HTTP method
  • 122.
  • 123. JavaFX HttpRequest function loadImageMetadata() { var start=page * 9; var request: HttpRequest = HttpRequest { location: &quot; http://localhost:8080/catalog/resources/items/ &quot; method: HttpRequest.GET onInput: function(input: java.io.InputStream) { var parser = PhotoPullParser{}; photos = parser.parse(input) ; } onDone: function() { updateImages() ; } } request.enqueue(); } Performs HTTP GET on url catalog/items
  • 124.
  • 125.
  • 126. Direct the parser with parser.forward() and parser.seek( QName{name:&quot;child&quot;} )
  • 127. JavaFX Parser public class PhotoPullParser { public function parse(input: InputStream): Photo[] { var photos: Photo[]; var photo: Photo; def parser = PullParser { input: input onEvent: function(event: Event) { if (event.type == PullParser.START_ELEMENT ) { if(event.qname.name == &quot;item&quot; and event.level == 1) { photo = Photo { }; } } else if (event.type == PullParser.END_ELEMENT ) { if( event.qname.name == &quot; item &quot; and event.level == 1) { insert photo into photos; } else if( event.qname.name == &quot; imagethumburl &quot; and event.level == 2){ photo.imagethumburl = event.text; } ... } } } parser.parse(); return photos; } <item> <imageurl>http://y.jpg</imageurl> <name>Friendly Cat</name> ... </item>
  • 128. Media
  • 129.
  • 130.
  • 132. support whatever the native platform (Windows, Mac, …) supports
  • 133. Integration with JavaFX scenegraph
  • 134. Example of Creating a Media Player var video :Media = Media { source: &quot;http://...&quot; }; var player :MediaPlayer = MediaPlayer { media: video rate: 1.0 volume: 0.4 }; var view :MediaView = MediaView { mediaPlayer: player x:200 y:200 }; Stage { title: &quot;Media Player&quot; width: 700 height: 700 scene: Scene { content: [view] } } controls for playing media Display for MediaPlayer Media source
  • 137.
  • 138. Carol McDonald Technology Evangelist [email_address]

Notes de l'éditeur

  1. escribe and present your product(s)/product line/service(s), technology, solution at a mid to high-level. Avoid low-level technical details (reserve to Systems Engineering training if needed) What are the business/technology value propositions? What is your BU vision and strategy? What OEM specific programs / resources do you have? How does your product/solution fit into an overall Sun open source /solution/story? JavaFX is the, Java-based, rich client platform for building RIA applications and content across multiple platforms Messages Designed to enable consistent user experiences, from desktop to mobile device to set-top box to Blu-ray Disc _________________________________________________ Zoom in on the FX portion of the Markecture diagram with a cool visual effect As Rich talks about a portion of Java FX, the component name is the only thing on the screen, high contrast, big font If there are cool visuals for the component, sprinkle them in
  2. Now here it is in JavaFX Script: Notice how both the frame&apos;s stage and the circle class use the same name for the background: fill. And if you want to get rid of the window&apos;s background you just set fill to null. It&apos;s consistent and easy. *that&apos;s* the value of creating a new API.
  3. The public-read Access Modifier The public-read access modifier defines a variable that is publicly readable, but (by default) is writeable only from within the current script. To widen its write access, prepend either the package or protected modifier (i.e. package public-read or protected public-read). Doing so will set its write access to the package or protected level. The public-init Access Modifier The public-init access modifier defines a variable that can be publicly initialized by object literals in any package. Subsequent write access, however, is controlled in the same manner as public-read (the default is write access at the script-level, but prepending package or protected will widen the access accordingly). The value of this variable is always readable from any package.
  4. Function An executable body of code that performs a particular task Function does not execute until it is invoked There are two levels of function: script level and object level Function can be a variable
  5. Classes extend classes or interfaces Scope modifiers: public, protected, package Implicitly “script private” init { } and postinit { } blocks take place of Constructors Functions and variables declared outside a class are static Multiple classes may be defined in a single Script
  6. Classes extend classes or interfaces Scope modifiers: public, protected, package Implicitly “script private” init { } and postinit { } blocks take place of Constructors Functions and variables declared outside a class are static Multiple classes may be defined in a single Script
  7. A Sequence represents an ordered list of objects; the objects of a sequence are called items. JavaFX has “Sequences”, not arrays A Sequence is an immutable ordered list of non-null elements JavaFX supports sequence comprehensions Sequences can be “sliced” Sequences can optimize memory usage
  8. bind is a way to tie the value of one variable to the value of an expression binding must be defined when the variable is initialized bindings are statically compiled bound variables cannot be set manually use bind with inverse for bidirectional binding
  9. The MoveTo class indicates the start point for the shape, and the ArcTo class creates an arc segment. All segments are combined into a shape using the Path class which represents a simple shape, and enables basic construction of a geometric path. The Path class is helpful when you need to create your own shape that is different from the primitive graphic shapes available in the javafx.scene.shape package. The Path class extends the Node class and inherits all of its instance variables and functions. Note: The sweepFlag instance variable is set to true so that the arc be drawn clockwise, in a &amp;quot;positive&amp;quot; angle. If the arcs are drawn counterclockwise, they will not curve correctly.
  10. The movement from the beginning to the end states, commonly called &amp;quot;tweening,&amp;quot; is specified with the tween operator. The Interpolator.LINEAR value means that movement will progress at a steady rate from the beginning position to the end position.