JavaFX Uni Parthenope

2,147 views

Published on

JavaFX: la piattaforma Java per le Rich Internet Application

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,147
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

JavaFX Uni Parthenope

  1. 1. JavaFX: la piattaforma Java per le Rich Internet Applications Corrado De Bari Software & Java Ambassador Sun Microsystems Italia Spa
  2. 2. Agenda ● What's news in Java Runtime Environment ● JavaFX Technology – Key Features – Architecture & Tools – JavaFX Script tutorial Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 2
  3. 3. New Features in 6u10 ● JavaKernel: faster download and install ● Java Quick Starter: faster applet start ● Rewritten Java Plugin – Applets run in own JVM – Unified desktop / browser deployment – Draggable Applet – Scriptable applets – Direct3D© support Try: http://download.java.net/javadesktop/plugin2/wwj/ Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  4. 4. Architectural Overview Applet 1 Applet 2 HTML Web Page Applet 3 Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 4
  5. 5. Architectural Overview ● Ground-up rewrite of the support for applets in the web browser ● Applets are no longer executed in a Java Virtual Machine (JVM™) inside the web browser ● Instead, a separate JVM machine process is launched to execute the applets ● By default, only one JVM machine is launched – Same resource consumption and sharing properties as the “classic” Java technology-based Plug-In ● Opportunity to launch more than one JVM machine – To support per-applet command-line arguments, heap size requests, and more ● Architectural similarities to Java Web Start software, but tighter browser integration Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  6. 6. Architectural Overview Client JVM 1 OS Process 2 Thin Server JVM OS Process 1 Client JVM 2 OS Process 3 Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 6
  7. 7. Compatibility ● Backward compatibility based on runs of hundreds of applets from throughout the web ● Applet lifecycle unchanged – init(), start(), stop(), destroy() ● All services supported: Browser proxy settings Browser certificate store Browser authenticator Browser cookie store Printing Java/JavaScript integration Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 7
  8. 8. JNLP Support Most significant new feature ● Unifies deployment between Java Web Start and the Java Plug-In – Simply choose the top-level container (Frame / Applet) ● Incorporate JNLP extensions trivially in applets – JavaFX run-time libraries, JOGL, Java 3D, JAI ● Use JNLP APIs from applets – PersistenceService, DownloadService, ... ● Full support for JVM command-line arguments, JRE version selection, JRE auto-download Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 8
  9. 9. Basic JNLP Example <applet width=”500” height=”500”> <param name=”jnlp_href” value=”my_applet.jnlp”> </applet> Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  10. 10. Basic JNLP Example <?xml version=”1.0” encoding=”UTF-8”?> <jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /> </jnlp> Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  11. 11. Applet-Desc Tag <?xml version=”1.0” encoding=”UTF-8”?> <jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /> </jnlp> Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  12. 12. Applet-Desc Tag ● width and height are ignored – Browser always overrides because it knows best how big the applet needs to be – Relative width and height supported in applet tag (i.e., “50%”) ● main-class parameter always used – code parameter from applet tag is ignored – Enables backward compatibility mechanisms (described later) Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  13. 13. Java / JavaScript Support ● Completely rewritten Java / JavaScript integration ● More complete, reliable and portable than before ● Formerly Mozilla-specific functionality now working in Internet Explorer – Static method access – Construction of new Java objects from JavaScript ● Respecifying and reintroducing “LiveConnect” Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 13
  14. 14. DOM Access Enables AJAX-style web apps using Java language ● DOM access via W3C APIs has been rewritten – Built on top of new Java/JavaScript support ● New, much simpler bootstrapping entry point org.w3c.dom.Document doc = com.sun.java.browser.plugin2.DOM. getDocument(applet); ● Can then cast to HTMLDocument and descend into the DOM ● Perform operations from any thread – Underlying Java/JavaScript bridge is thread safe Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 14
  15. 15. Support for Advanced Applets ● Control over Java heap size ● Control over Java 2D acceleration parameters ● Ideal environment for running 3D content ● JOGL applet examples – NASA World Wind Java: ● http://download.java.net/javadesktop/plugin2/wwj/ – Jake2 – Bytonic Software: ● http://www.bytonic.de/downloads/jake2_jogl11.jnlp Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 15
  16. 16. JavaFX JavaFX is THE platform for creating and delivering Rich Internet Applications across all the screens of your life JavaFX is Powered by Java Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  17. 17. Key Features ✔ One-stop shop RIA platform for all screens: ✔ Build engaging visual experiences across desktop, browser and mobile with a unified development and deployment model. ✔ Broadest market reach: ✔ Distribute RIAs easily across billions of devices with the power of Java. ✔ Designer-developer workflow: ✔ Dramatically shorten your production cycle for design and development. Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  18. 18. Key Features (Continued) ✔ Powerful runtime: ✔ Leverage the extreme ubiquity, power, performance and security of the Java runtime. ✔ Break free from the browser: ✔ Drag-and drop a JavaFX application from the browser to deploy to the desktop. ✔ Java technology compatibility: ✔ Preserve your investment by enabling the use of any Java library within a JavaFX application. Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  19. 19. What you can do: Simple Video Player •Incorporating video in your application is as simple as creating an instance of this component, setting a few variables and including a link to your video source. Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  20. 20. 3-D Display Shelf: the Perspective Transform •The PerspectiveTransform built into JavaFX can be used to easily create 3-D effects Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  21. 21. Flying Saucer •The new out-of-process Java applet plugin in Java SE 6 update 10 enables you to make applets which can run outside of the browser. Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  22. 22. Demo: JavaFX apps http://www.javafx.com/samples/EffectsPlayground/webstart/EffectsPlayground.jnlp http://www.javafx.com/samples/DraggableMP3Player/webstart/DraggableMP3Player.jnlp http://www.javafx.com/samples/BrickBreaker/webstart/BrickBreaker.jnlp Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  23. 23. JavaFX architecture Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  24. 24. JavaFX roadmap Desktop Product Line JavaFX Desktop (Winter 2008) Mobile Product Line JavaFX Mobile (Spring 2009) TV Product Line JavaFX TV (Summer 2009) Other Platforms With Partner platforms/OSs Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 24
  25. 25. JavaFX Tools: rel 1.2 NetBeans IDE 6.5.1 for JavaFX 1.2 JavaFX 1.2 Production Suite ✔ Windows XP, Windows Vista ✔ Adobe Illustrator CS3/CS4 ✔ Mac OS X 10.4.10 minimum ✔ Adobe Photoshop CS3/CS4 ✔ Ubuntu 8.04 LTE ✔ OpenSolaris 2009.06 Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 25
  26. 26. JavaFX Tools JavaFX 1.2 Plugin for Adobe Photoshop and JavaFX 1.0 Plugin for Adobe Illustrator JavaFX 1.2 Media Factory ✔SVG Importer/Transcoder ✔Viewer Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 26
  27. 27. How to Deploy ● Java Plugin ● Java Web Start ● JavaFX 1.0 Mobile Emulator Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 27
  28. 28. JavaFX APIs ● JavaFX Scene – Node based GUI framework ● JavaFX Media – Media player, native and cross platform codecs ● JavaFX Web Services – REST-ful – RSS ● JavaFX Profiles – Common – Desktop – Mobile Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  29. 29. JavaFX Script ● Created for rapid and easy GUI creation ● Object-oriented – Namespaces, Classes, attributes, functions and operations ● Declarative syntax ● Both static-typing & type-inference ● Animation, data binding and event handing built in Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  30. 30. Example: Hello World in Swing import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new JFrame(quot;HelloWorld Swingquot;); final JLabel label = new JLabel(quot;Hello Worldquot;); frame.getContentPane().add(label); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 30
  31. 31. Example: Hello World in JavaFX Declarative Syntax Frame { title: quot;Hello World JavaFXquot; width: 200 height: 100 visible: true stage: Stage { content: [Text { font: Font { size: 24 style: FontStyle.PLAIN } x: 10, y: 30 content: quot;Hello Worldquot; }] } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 31
  32. 32. Class Definition •Address class definition: The Address class declares street, city, state, and zip instance variables all of type String class Address { var street: String; var city: String; var state: String; var zip: String; } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  33. 33. Class Definition •Customer class definition with functions - functions are like methods in Java class Customer { var firstName: String; var lastName: String; var phoneNum: String; var address: Address; function printName() { println(quot;Name: {firstName} {lastName}quot;); } function printPhoneNum(){ println(quot;Phone: {phoneNum}quot;); } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  34. 34. Create an Object •Nesting Address object inside Customer object def customer = Customer { firstName: quot;Johnquot;; lastName: quot;Doequot;; phoneNum: quot;(408) 555-1212quot;; address: Address { street: quot;1 Main Streetquot;; city: quot;Santa Claraquot;; state: quot;CAquot;; zip: quot;95050quot;; } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  35. 35. Step by Step Process of Creating a simple GUI •JavaFX application that renders a green rounded rectangle and a white circle with red outline on the top of the rectangle Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  36. 36. Step by Step Process of Creating a GUI 1.Add necessary imports 2.Create an Application window 3.Set the Scene 4.Create a Rectangle 5.Create a Circle 6.Change the code (so that the Circle gets underneath the Rectangle) Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  37. 37. 1. Add Necessary Imports import javafx.stage.Stage; // required to render a window import javafx.scene.Scene; // required to display a circle and // rectangle on a window import javafx.scene.shape.Rectangle; // required to render the rectangle import javafx.scene.paint.Color; // required to fill and stroke the // rectangle and circle with color import javafx.scene.shape.Circle; // required to render the circle Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  38. 38. 2. Create an Application Window •In order to display the graphics, you need to create a window through Stage object literal // Create a Stage object literal. Stage is required to render any object. // The window should be big enough to display all of the rectangle and // the circle. In this example, the window is a rectangle of 249 by 251 // pixels. To create a window of this size, with a quot;Declaring is Easyquot; title, // declare these values within the curly brackets using the following code: Stage { title: quot;Declaring Is Easy!quot; width: 249 height: 251 visible: true } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  39. 39. 3. Set the Scene •Within the stage, set the scene to hold Node objects such as a circle or a rectangle •The scene is a root area where you place objects of the node type. •The scene has content variable that is used to hold the nodes. •There are many different kinds of nodes, such as graphical objects, text, and GUI components. Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  40. 40. 3. Set the Scene (Continued) •// The content of the window becomes filled with white because // white is a default fill color for a scene. The scene is placed on top // of the window. Stage { ... scene: Scene { content: [ ] } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  41. 41. 4. Create a Rectangle Stage { ... scene: Scene { content: [ // The x and y instance variables specify the pixel location of the // rectangle, arcWidth and arcHeight define the roundness of // corners, and the fill variable defines the color that fills the rectangle. Rectangle { x: 45 y: 35 width: 150 height: 150 arcWidth: 15 arcHeight: 15 fill: Color.GREEN } ] } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  42. 42. 5. Create a Circle Stage { ... scene: Scene { content: [ Rectangle { ... }, // Because the rectangle is declared before any other objects, it is painted // first. The rectangle will be behind any other objects painted later. Circle{ centerX: 118 centerY: 110 radius: 83 fill: Color.WHITE stroke: Color.RED } ] } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  43. 43. 6. Place Circle Underneath Rectangle Stage { ... scene: Scene { content: [ // Place the circle underneath the square. To do so, switch the order // of the circle and square Circle{ .... }, Rectangle { ... } ] } } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  44. 44. Effects: DropShadow Text { effect: DropShadow { offsetY: 3 color: Color.color(0.4, 0.4, 0.4) }; ... }, Circle { effect: DropShadow { offsetY: 4 }, ... } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  45. 45. Images ImageView = ImageView { clip: Rectangle { y: 30 x: 50 width: 350 height: 100 } image: Image { url: quot;...quot;} } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 45
  46. 46. JavaFX Script: Data Binding // will be modified elsewhere var count:Integer = new Integer(); // The label text is bound to the count Label { text: bind count.value.toString( ) } Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  47. 47. JavaFX Script: Event Triggers // Triggering validation of the // number of wheels on a vehicle attribute numWheels:Integer = 4 on replace (oldValue) { if (numWheels <= 0) { System.out.println(quot;{numWheels} wheels not valid, changing back to {oldValue}!quot;); numWheels = oldValue; } }; Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009
  48. 48. Resources ● JavaPassion Trainings (Source of this presentation): – http://www.javapassion.com/javafx ● http://www.javafx.com/ ● http://java.sun.com/javase/downloads/index.jsp ● http://java.sun.com/javase/6/webnotes/6u10.html ● http://scenegraph.dev.java.net/ ● http://jogl.dev.java.net/ Sun Microsystems Proprietary TechDay 09 – UniParthenope, 4 giugno 2009 48
  49. 49. JavaFX: la piattaforma Java per le Rich Internet Applications Corrado De Bari Software & Java Ambassador Sun Microsystems Italia Spa

×