Java FX 2.0 - A Developer's Guide

  • View
    16.772

  • Download
    0

Embed Size (px)

DESCRIPTION

A University talk about JavaFX 2.0 do

Text of Java FX 2.0 - A Developer's Guide

  • 1.JavaFX 2.0 A Java Developers GuideStephen ChinChief Agile Methodologist, GXShttp://steveonjava.com @steveonjavaPeter PilgrimOracle Java Championhttp://www.xenonique.co.uk/blog/ @peter_pilgrim

2. Meet the PresentersStephen Chin Peter Pilgrim@steveonjava@peter_pilgrimFootball, Music &Partner Family Man Motorcyclist 3. This is a Participatory Session!> Every now and then we will say something interesting and it will go out in a tweet.> Follow @steveonjava to watch the tweets and retweet the ones you like to your followers> Feel free to create your own tweets using the hash tags "#JavaFX #Devoxx"> We have some goodies for folks who play. J 3 4. At the end of the day, on the onehand we have computer systems,and on the other, people.Connecting them together, andallowing people to interact withcomputer systems in a compellingway, requires graphical userinterfacesChris Oliver, Creator of F3http://blogs.oracle.com/chrisoliver/entry/epitaph4 5. JavaFX 2.0 PlatformImmersive Desktop ExperienceCombining the Best of JavaFX and WebTechnologies> Leverage your Java skills with modern JavaFX APIs> Integrate Java, JavaScript, and HTML5 in the same application> New graphics stack takes advantage of hardware acceleration for 2D and 3D applications> Integrate in Swing applications using JFXPanel> User your favorite IDE: NetBeans, Eclipse, IntelliJ, etc. 6. DemoVideo Fracture 7. Headline News> RT @Stephan007: The #JavaOne11 channel on #Parleys passed 51.800 views! Most viewed: "Introduction to #JavaFX 2.0", close to 11,000 - @JavaFX4You, 9th November 2011> The most interesting announcement came when Oracle demoed both Java and JavaFX applications running on a Windows tablet, an iPad, and a "Linux-based tablet". - Eric Bruno, Dr Dobbs Journal, 5th October 2011 7 8. Platform Support> Windows fully supported l For 3D you need one of the supported graphics cards (ATI, NVidia, Intel)> Mac OS X preview available> Linux Planned for end of 2012 8 9. Windows OS RequirementsOperating System (32-Bit and 64-Bit) Browsers (32-Bit and 64-Bit)Windows XP Home and Professional Internet Explorer 7 and 8with Service Pack 3ChromeWindows Vista Home Basic, Home Internet Explorer 7, 8, and 9Premium, Business, and Ultimate with Firefox 3.5, 3.6, and 4Service Pack 2 ChromeWindows 7 Home Premium,Internet Explorer 8 and 9Professional, and Ultimate Firefox 3.5, 3.6, and 4 Chrome 9 10. Supported Graphics CardsSupported Graphics ProcessingGraphics Card Units (GPUs)NVIDIAMobile GPUs: GeForce 8M and 100Mseries or higher, NVS 2100M series orhigher, and Mobility Quadro FX 300Mseries or higherDesktop GPUs: GeForce 8 and 100series or higherWorkstation GPUs: Quadro FX 300series or higherATI Mobile GPUs: Mobility Radeon HD3000, 4000, and 5000 seriesDesktop GPUs: Radeon HD 2400,3000, 4000, 5000, and 6000 seriesIntel Mobile GPUs: GMA 4500MHD andGMA HDDesktop GPUs: GMA 4500 and GMAHD10 11. Building JavaFX Applications> Deploys in the browser or on desktop> Pure Java APIs> Includes builders for declarative construction> Alternative languages can also be used for simpler UI creation l GroovyFX l ScalaFX l Visage11 12. Hello Devoxx (Java Version)public class HelloDevoxx extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Hello Devoxx"); Group root = new Group(); 19 Lines Scene scene = new Scene(root, 400, 250, Color.ALICEBLUE); Text text = new Text(); Characters 425 text.setX(105); text.setY(120); text.setFont(new Font(30)); text.setText("Hello Devoxx"); root.getChildren().add(text); primaryStage.setScene(scene); primaryStage.show(); } } 12 13. Hello Devoxx (Builder Version)public void start(Stage primaryStage) { primaryStage.setTitle("Hello Devoxx"); primaryStage.setScene(SceneBuilder.create() .width(400) .height(250) .fill(Color.ALICEBLUE) .root( 25 Lines GroupBuilder.create().children( TextBuilder.create() .x(105) 418 Characters .y(120) .text("Hello Devoxx") .font(new Font(30)) .build() ).build() ) .build()); primaryStage.show(); } 13 14. Hello Devoxx (GroovyFX Version)GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() sg.stage( title: Hello Devoxx, show: true) { scene( fill: aliceblue, 17 Lines width: 400, height: 250) { Characters190 text( x: 105, y: 120, text: "Hello Devoxx" font: "30pt") } } } 14 15. Hello Devoxx (ScalaFX Version)object HelloDevoxx extends JFXApp { stage = new Stage { title = "Hello Devoxx" width = 400 height = 250 scene = new Scene { fill = BLUE Lines16 Text { 163 Characters x = 105 y = 120 text = "Hello Devoxx" font = Font(size: 30) } } } } 15 16. Hello Devoxx (Visage Version)Stage { title: "Hello Devoxx" width: 400 height: 250 scene: Scene { fill: BLUE 14 Lines content: Text { Characters129 x: 105 y: 120 text: "Hello Devoxx" font: Font {size: 30pt} } } } 16 17. Architecture of JavaFX 2.0 JavaFX Public APIQuantum ToolkitPrism Glass Media Web WinTk Engine EngineJava2DOpen GLD3D Java Virtual Machine 18. JavaFX 2.0FundamentalsProperties, Lists, Binding 18 19. JavaFX 2.0 Properties> Primitive Properties> Object Properties> FX List Collection Properties> Properties are: l Observable l Lazy l Type Safe 19 20. Properties in Java Property Declarationpublic class Person { private StringProperty rstName; public void setFirstName(String val) { rstNameProperty().set(val); } public String getFirstName() { return rstNameProperty().get(); } public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName"); return rstName; } } 20 21. Properties in Javapublic class Person { private StringProperty rstName; public void setFirstName(String val) { rstNameProperty().set(val); } public String getFirstName() { return rstNameProperty().get(); Setter Method } (Convenience) public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName"); return rstName; } } 21 22. Properties in Javapublic class Person { private StringProperty rstName; Getter Method public void setFirstName(String val) { (Convenience) rstNameProperty().set(val); } public String getFirstName() { return rstNameProperty().get(); } public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName"); return rstName; } } 22 23. Properties in Javapublic class Person { private StringProperty rstName; public void setFirstName(String val) { Property Fetcher rstNameProperty().set(val); (Lazy Construction) } public String getFirstName() { return rstNameProperty().get(); } public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName"); return rstName; } } 23 24. Properties in Javapublic class Person { private StringProperty rstName; Even Lazier public void setFirstName(String val) { rstNameProperty().set(val); } public String getFirstName() { return rstName == null ? null : rstNameProperty().get(); } public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName"); return rstName; } } 24 25. Properties in Javapublic class Person { private StringProperty rstName; public void setFirstName(String val) { With initial value rstNameProperty().set(val); } public String getFirstName() { return rstName == null ? "Peter" : rstNameProperty().get(); } public StringProperty rstNameProperty() { if (rstName == null) rstName = new SimpleStringProperty(this, "rstName", "Peter"); return rstName; } } 25 26. DemoPropertiesUndirectional, Bidirectional andLazy binding in Java 27. Listeners> Change Listener l Observable, old value, new value> Invalidation Listeners l Observable27 28. Property Listener Example IntegerProperty temperature = new SimpleIntegerProperty(0); temperature.setOnChangeListener( new ChangeListener() { public void change( ObservableValue