java fx part2

18
Introduction of JavaFx Prem Chand Mali

Upload: mindfire-solutions

Post on 27-Jan-2015

111 views

Category:

Technology


5 download

DESCRIPTION

JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.This presentation covers event handling and new features of the JavaFx.

TRANSCRIPT

Page 1: Java FX Part2

Introduction of JavaFxPrem Chand Mali

Page 2: Java FX Part2

About MeSCJP/OCJP - Oracle Certified Java ProgrammerMCP:70-480 - Specialist certification in HTML5

with JavaScript and CSS3 Exam

Skills : Java, Swings, Springs, Hibernate, JavaFX, Jquery, prototypeJS, ExtJS.

Connect Me :Facebook : https://www.facebook.com/prem.c.maliLinkedIn: http://www.linkedin.com/in/premmaliTwitter: https://twitter.com/prem_maliGoogle+ : https://plus.google.com/106150245941317924019/about/p/pub

Contact Me :Email : [email protected] / [email protected]: mfsi_premchandm

Page 3: Java FX Part2

Agenda

Event Handling.

Property and Bindings

WebView and MediaPlayer

Shapes

Bind event on shapes

Q&A

Page 4: Java FX Part2

Event Handling

What is an event ?

Event types

Event targets

Event delivery process

Page 5: Java FX Part2

What is an event ?

Event is occurrence which happens in application with or without participation of human.

JavaFx events are instance of javafx.event.Event or subclass of Event.

Event has following three properties.

– Event type : Type of event

– Source : Origin of the event, source changes as the event is passed along the chain.

Target: No on which the action occurred

Page 6: Java FX Part2

Event Type

An event type is an instance of the EventType class.

Event.Any

WindowEvent.Any ActionEvent.Action InputEvent.Any

MouseEvent.AnyKeyEvent.Any

MouseEvent.Mouse_Pressed

KeyEvent.Any

KeyEvent.Key_Pressed

KeyEvent.Key_Released

...

MouseEvent.Mouse_Released

WindowEvent.Showing

WindowEvent.Shown

Page 7: Java FX Part2

Event Target

• Target can be instance of any class that implements EventTarget interface.

• Implementation of buildEventDispatchChain creates the event dispatch chain that the event must travel to reach target.

• Window, scene, node classes implement the EventTarget interface and subclasses of those classes inherit the implementation.

• If custom control is not subclass from Window, Scene, or Node then you need to implement EventTarget.

Page 8: Java FX Part2

Event delivery process

• Event delivery process contains following four steps

– Target Selection

– Route construction

– Event capturing

– Event bublling

Page 9: Java FX Part2

Properties and Binding

• JavaBeans component architecture to represent the property of an object. JavaFx expended and improved it.

• JavaFX properties are often used in conjunction with binding, a powerful mechanism for expressing direct relationships between variables.

• Properties classes is part of javafx.beans.property package.

• A binding observes its list of dependencies for changes, and then updates itself automatically after a change has been detected. It is following two types of API

– High Level– Low Level

Page 10: Java FX Part2

Properties and Binding

Fluent API

IntegerProperty num1 = new SimpleIntegerProperty(1);IntegerProperty num2 = new SimpleIntegerProperty(2);NumberBinding sum = num1.add(num2);

System.out.println(sum.getValue());

num1.set(2);System.out.println(sum.getValue());

Binding class

NumberBinding sum = Bindings.add(num1,num2);

Both Approach

Bindings.add(num1.multiply(num2),num3.multiply(num4));

Page 11: Java FX Part2

Properties and Buinding

Low Level API example

DoubleBinding db = new DoubleBinding() { { super.bind(a, b, c, d); } @Override protected double computeValue() { return (a.get() * b.get()) + (c.get() * d.get()); } };

Page 12: Java FX Part2

WebView

The WebView component is based on WebKit, an open source web browser engine. It supports Cascading Style Sheets (CSS), JavaScript, Document Object Model (DOM), and HTML5.

It enables you to perform following tasks.

– Render HTML content from local and remote URLs– Obtain Web history– Execute JavaScript commands– Perform upcalls from JavaScript to JavaFX– Manage web pop-up windows– Apply effects to the embedded browser

Page 13: Java FX Part2

Media

The javafx.scene.media package enables developers to create media applications that provide media playback in the desktop window or within a web page on supported platforms.

Currently supported formats.

– Audio: MP3; AIFF containing uncompressed PCM; WAV containing uncompressed PCM; MPEG-4 multimedia container with Advanced Audio Coding (AAC) audio

– Video: FLV containing VP6 video and MP3 audio; MPEG-4 multimedia container with H.264/AVC (Advanced Video Coding) video compression.

Page 14: Java FX Part2

Media

Some of the features supported by the JavaFX media stack include the following

– FLV container with MP3 and VP6– MP3 audio– MPEG-4 container with either AAC, H.264, or both– HTTP, FILE protocol support– Progressive download– Seeking– Buffer progress– Playback functions (Play, Pause, Stop, Volume,

Mute, Balance, Equalizer)

Media components – Media – A media resource, containing information

about the media, such as its source, resolution, and metadata.

– MediaPlayer – The key component providing the controls for playing media.

Page 15: Java FX Part2

Media

Media components – MediaView – A Node object to support animation,

translucency, and effects

Page 16: Java FX Part2

Shapes

• JavaFx also provided capability to draw following shapes on scene.

– Circle

– Rectangle

– Ellipse

– Line

– Polygon

– etc

Page 17: Java FX Part2

Events on Shapes

• JavaFx Shape API also provide capability to add event on Shapes.

For example :

rect.setOnMouseClicked(new EventHandler<MouseEvent>() {

@Override public void handle(MouseEvent event) { Color color = (((Color) rect.getFill()).equals(Color.RED)) ? Color.BROWN : Color.RED; rect.setFill(color); } });

Page 18: Java FX Part2

Q&A