Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Java SE 6 Update 10
& JavaFX:
la piattaforma Java
per le RIA
1Corrado De Bari
Software & Java Ambassador
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
2
Sun Microsystems Proprietary
Agenda
●
What's news in Java Runtime Environment
●
JavaFX Technology
–
Key Features
–
Architecture & Tools
–
JavaFX Script tutorial
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
4
Sun Microsystems Proprietary
Architectural Overview
HTML Web Page
Applet 1
Applet 2
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
6
Sun Microsystems Proprietary
Architectural Overview
Thin Server JVM
Client JVM 1
Client JVM 2
OS Process 1
OS Process 2
OS Process 3
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
7
Sun Microsystems Proprietary
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
showDocument() support
Printing
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
8
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Basic JNLP Example
<applet width=”500” height=”500”>
<param name=”jnlp_href”
value=”my_applet.jnlp”>
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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>
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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” />
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
13
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
14
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
15
Sun Microsystems Proprietary
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:
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
JavaFX
JavaFX is
THE
platform for creating and
delivering
Rich Internet Applications
across all the screens of your life
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
3-D Display Shelf: the
PerspectiveTransform
•
The PerspectiveTransform built into JavaFX
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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.
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
24
Sun Microsystems Proprietary
JavaFX roadmap
JavaFX
Desktop
(Winter 2008)
JavaFX
Mobile
(Spring 2009)
JavaFX TV
(Summer 2009)
Desktop Product Line
Mobile Product Line
TV Product Line
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
25
Sun Microsystems Proprietary
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
26
Sun Microsystems Proprietary
JavaFX Tools
JavaFX 1.0 Plugin for Adobe
Photoshop and JavaFX 1.0
Plugin for Adobe Illustrator
JavaFX 1.0 Media Factory
✔
SVG Converter
✔Viewer
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
27
Sun Microsystems Proprietary
How to Deploy
●
Java Plugin
●
Java Web Start
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
JavaFX APIs
●
JavaFX Scene
–
Node based GUI framework
●
JavaFX Media
–
Media player, native and cross platform codecs
●
JavaFX Web Services
–
REST-ful
●
JavaFX Profiles
–
Common
–
Desktop
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
30
Sun Microsystems Proprietary
Example: Hello World in Swing
import javax.swing.*;
public class HelloWorldSwing {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorld Swing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
31
Sun Microsystems Proprietary
Example: Hello World in JavaFX
Declarative Syntax
Frame {
title: "Hello World JavaFX"
width: 200
height: 100
visible: true
stage: Stage {
content: [Text {
font: Font {
size: 24
style: FontStyle.PLAIN
}
x: 10, y: 30
content: "Hello World"
}]
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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;
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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("Name: {firstName} {lastName}");
}
function printPhoneNum(){
println("Phone: {phoneNum}");
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Create an Object
•
Nesting Address object inside Customer
object
def customer =
Customer
{
firstName: "John";
lastName: "Doe";
phoneNum: "(408) 555-1212";
address:
Address
{
street: "1 Main Street";
city: "Santa Clara";
state: "CA";
zip: "95050";
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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 "Declaring is Easy" title,
// declare these values within the curly brackets using the following
code:
Stage {
title: "Declaring Is Easy!"
width: 249
height: 251
visible: true
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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.
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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: [ ]
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
}
]
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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
}
]
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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 {
...
}
]
}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Effects: DropShadow
Text {
effect: DropShadow {
offsetY: 3
color: Color.color(0.4, 0.4, 0.4)
};
...
},
Circle {
effect: DropShadow {
offsetY: 4
},
...
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
45
Sun Microsystems Proprietary
Images
ImageView = ImageView {
clip: Rectangle {
y: 30 x: 50
width: 350 height: 100
}
image: Image { url: "..."}
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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( )
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
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("{numWheels} wheels not valid,
changing back to {oldValue}!");
numWheels = oldValue;
}
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
48
Sun Microsystems Proprietary
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/
Corrado De Bari - [email protected] - Sun Microsystems Italia
Javaday Roma III Edizione – 24 gennaio 2009
Sun Microsystems Proprietary
Java SE 6 Update 10
& JavaFX:
la piattaforma Java
per le RIA
49Corrado De Bari
Software & Java Ambassador