exploring javafx 8 - oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/a3-javaday...46 the...

46
1 Exploring JavaFX 8 Stephen Chin (@steveonjava) Java Technology Ambassador JavaOne Content Chair jdt2014_A3

Upload: others

Post on 02-Jan-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

1

Exploring JavaFX 8

Stephen Chin (@steveonjava)

Java Technology Ambassador

JavaOne Content Chair

♯jdt2014_A3

Page 2: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

2

• Cross-platform Animation, Video, Charting

• Integrate Java, JavaScript, and HTML5 in the

same application

• New graphics stack takes advantage of hardware

acceleration for 2D and 3D applications

• Bidirectional integration with Swing applications

using JFXPanel and SwingNode

Immersive Application Experience

JavaFX Platform

Page 3: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

3

How to Get JavaFX

Step 1: Download Java 8

Page 4: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

4

How to Develop JavaFX Use Your Favorite IDE

Page 5: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

5

Architecture of JavaFX 8

Java Virtual Machine

Java2D Open GL D3D

Prism Glass

WinTk

Media

Engine

Web

Engine

JavaFX Public API

Quantum Toolkit

Page 6: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

6

Package Your Application Applets, Web Start, and Native Packaging

Good Better Best

Page 7: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

7

New Features in JavaFX 8

Page 8: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

Controls

Page 9: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

9

DatePicker

Allows selection of dates

and ranges

Can use custom formats

and calendars

Supports Cascading Style

Sheets

Page 10: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

10

TreeTableView

Combines a TreeView and a

TableView

Optional menu for hiding and

showing columns

Root can be hidden

Supports multiple selection

Supports CSS

Page 11: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

11

New Modena UI Theme

Page 12: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

12

Page 13: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

13

Build Applications Visually JavaFX Scene Builder 2

Page 14: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

14

Page 15: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

15

Displaying HTML in JavaFX

public class WebViewTest extends Application {

public static void main(String[] args) {

launch(WebViewTest.class, args);

}

@Override public void start(Stage stage) {

WebView webView = new WebView();

webView.getEngine().load("http://google.com");

Scene scene = new Scene(webView);

stage.setScene(scene);

stage.setTitle("Web Test");

stage.show();

}}

Page 16: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

16

Displaying HTML in JavaFX

Page 17: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

17

Calling Javascript from JavaFX

String script = "alert('We have got a message, Houston!');”;

eng.executeScript(script);

Page 18: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

18

JavaScript to Java Type Conversion

JavaScript Java

null null

undefined “undefined”

number java.lang.Number (Integer or

Double)

string java.lang.String

boolean java.lang.Boolean

object netscape.javascript.JSObject

Page 19: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

19

Responding to Browser Events

Alert/Confirm/Prompt – Respond to JavaScript user interaction

functions

• Resize – Web page moves or resizes the window object

• Status – Web page changes the status text

• Visibility – Hide or show the window object

• Popup – Spawn a second web view/engine

Page 20: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

20

HTML5 Features

Canvas and SVG

Media playback

Form controls

History maintenance

Interactive element tags

DOM

Web workers*

Web sockets*

Web fonts*

* = new in HTML5

Page 21: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

21

The Java Conference Tour app

Page 22: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

22

JAVAFX 3D

Page 23: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

23

Mesh Geometry (3D Shapes)

■ Predefined shapes

■ Box

■ Cylinder

■ Sphere

■ User-defined shapes

■ Using TriangleMesh / MeshView

23

https://wikis.oracle.com/display/OpenJDK/SphereAndBox.java

Page 24: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

24 24

Creating Primitive Shapes and Materials

Page 25: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

25 25

Rotating the 3D Shapes

Tip: Use lambda expressions as

shown here to simplify event handling

Page 26: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

26

3D Materials and Textures

■ PhongMaterial has these properties

■ Ambient color

■ Diffuse color, diffuse map

■ Specular color, specular map

■ Specular power

■ Bump map

■ Self-illumination map

26

https://wikis.oracle.com/display/OpenJDK/3D+Features

Page 27: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

27

UV Mapping Textures to Shapes

27

Tip: A texture is a 2D image to

be mapped on a 3D surface

Source: http://en.wikipedia.org/wiki/File:UVMapping.png

Page 28: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

28

Placing a Texture on a Sphere

28

Page 29: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

29

Placing a Texture on a Sphere

29

Page 30: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

30

UV Mapping on a Cube

30

Page 31: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

31

Understanding TriangleMesh

31

8 points

12 faces

14 texCoords

12 faces

Image

0, 0

0, 1

1, 0

1, 1

Tip: Best practice

for texture map

dimensions is

powers of two

(e.g. 1024x512)

Page 32: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

32

Using TriangleMesh Points

32

Tip: The API for points,

texCoords, and faces is

currently being modified,

primarily to hold this data

in different structures.

(For example)

Page 33: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

33

Using TriangleMesh Texture Coords

33

(For example)

Page 34: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

34

Using TriangleMesh Faces

34

0, 2, 1 are points[] indices

10, 5, 9 are texCoords[] indices

Page 35: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

35

Using TriangleMesh Smoothing Groups

35

These are faces[] indices

(and putting all the pieces together of our user-defined shape)

Page 36: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

36 36

Real-World Example of Mesh Geometry

Page 37: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

37

3D Lights

■ Lights are nodes in the scene graph

■ PointLight

■ AmbientLight

■ Default light provided if no active lights

37

https://wikis.oracle.com/display/OpenJDK/3D+Features

Page 38: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

38 38

Lights, Camera, Action!

Tip: The camera is also a node in

the scene graph, so it is moveable

Page 39: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

39

=

Have Java With Your Dessert Raspberry Pi

Page 40: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

40 http://elinux.org/File:Raspi-Model-AB-Mono-2-699x1024.png

Page 41: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

41

Embedded Controls Theme

Page 42: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

42

Virtual Keyboard

Page 43: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

43

JavaFX on Raspberry Pi Gotchas

WebView Media

Page 44: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

44

And you can do cool stuff like this… https://bitbucket.org/stephanj/tweetwall

Page 45: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

45

Stephen Chin tweet: @steveonjava

blog: http://steveonjava.com

nighthacking.com

Real Geeks Live Hacking

NightHacking Tour

Page 46: Exploring JavaFX 8 - Oracleotndnld.oracle.co.jp/ondemand/javaday2014/pdf/A3-JavaDay...46 The preceding is intended to outline our general product direction. It is intended for information

46

The preceding is intended to outline our general product direction. It is intended

for information purposes only, and may not be incorporated into any contract.

It is not a commitment to deliver any material, code, or functionality, and should

not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products

remains at the sole discretion of Oracle.