31
Rich Internet Applications con JavaFX e NetBeans A cura di: Fabrizio Giudici

Rich Internet Applications con JavaFX e NetBeans

Embed Size (px)

Citation preview

Page 1: Rich Internet Applications  con JavaFX e NetBeans

Rich Internet Applications

con JavaFX e NetBeans

A cura di:

Fabrizio Giudici

Page 2: Rich Internet Applications  con JavaFX e NetBeans

Introduction

• JavaFX, an “umbrella” for RIA– JavaFX Script– Desktop runtime– JavaFX Mobile– More to come (design tools?)

• NetBeans, an IDE– Java and other languages

Page 3: Rich Internet Applications  con JavaFX e NetBeans

Context

• Will compete with– Adobe's Flash/Flex/Air– Microsoft Silverlight

• Based on the Java Virtual Machine• Upcoming “Consumer JRE”

– See “Java 6 Update N”

Page 4: Rich Internet Applications  con JavaFX e NetBeans

It's what you're thinking...

It is intended to make Applets!(among others)

Page 5: Rich Internet Applications  con JavaFX e NetBeans

Samples

Page 6: Rich Internet Applications  con JavaFX e NetBeans

JavaFX Script

• Object oriented• Declarative• Statically typed• Can access the whole Java Runtime

– Comes with runtime extensions

• Currently interpreted– Compiler coming soon

Page 7: Rich Internet Applications  con JavaFX e NetBeans

An example

import javafx.ui.*;

Frame { title: "Hello World JavaFX" width: 200 height: 50 content: Label { text: "Hello World" } visible: true }

Page 8: Rich Internet Applications  con JavaFX e NetBeans

Procedural fashion too

var win = new Frame(); win.title = "Hello World JavaFX"; win.width = 200; var label = new Label(); label.text = "Hello World"; win.content = label; win.visible = true;

Page 9: Rich Internet Applications  con JavaFX e NetBeans

Model / View / Controller

• MVC is a foundation, of course• JavaFX allows to minimize the

boilerplate code between M and VC• Binding

– Incremental– Bidirectional

Page 10: Rich Internet Applications  con JavaFX e NetBeans

Binding

class HelloWorldModel { attribute saying: String; } var model = HelloWorldModel { saying: "Hello World" }; Frame { title: "Hello World JavaFX" width: 200 content: Label { text: bind model.saying } visible: true };

Page 11: Rich Internet Applications  con JavaFX e NetBeans

Basic components (widgets)

• Border• LayoutManager• Menu• Label• GroupPanel• Button

• ListBox• RadioButton...• ComboBox• Tree, Table• TextComponents• Spinner, Slider

Page 12: Rich Internet Applications  con JavaFX e NetBeans

Changes from plain Swing

• LayoutManager → LayoutPanel• GroupPanel is supported• StackPanel

Page 13: Rich Internet Applications  con JavaFX e NetBeans

Listeners

• Similar concept, different implementation than Swing– operations (methods) can be defined on

the fly– no inner classes

Page 14: Rich Internet Applications  con JavaFX e NetBeans

A Listener example

Button { text: "I'm a button!" mnemonic: I action: operation() { model.numClicks++; }

Page 15: Rich Internet Applications  con JavaFX e NetBeans

Labels

• Can contain HTML• HTML can contain dynamic parts

Page 16: Rich Internet Applications  con JavaFX e NetBeans

Dynamic HTML example content: Label { text: bind "<html> <h2 align='center'>Shopping Cart</h2> <table align='center' ...> <tr bgcolor='#cccccc'> <td><b>Item ID</b></td> <td><b>Available</b></td> <td><b>List Price</b></td> <td> </td> </tr>

{ if (sizeof cart.items == 0) then "<tr><td'><b>Your cart is empty.</b></td></tr>" else foreach (item in cart.items) "<tr><td>{if item.inStock then "Yes" else "No"}</td> <td align='right'>{item.totalCost}</td></tr>" } </table> </html>" }

Page 17: Rich Internet Applications  con JavaFX e NetBeans

Too many words! Let's go coding!

Page 18: Rich Internet Applications  con JavaFX e NetBeans

The application

Page 19: Rich Internet Applications  con JavaFX e NetBeans

Steps

• Get introduced to NetBeans• Create model classes• Create and bind some UI element• Events• Advanced stuff (search)• Integration with other tiers

Page 20: Rich Internet Applications  con JavaFX e NetBeans

Model classes

• Person, Email, PhoneNumber• PersonFactory• PersonListModel

Page 21: Rich Internet Applications  con JavaFX e NetBeans

Triggers

trigger on new PersonListModel { personFactory.load(); detailPane.person = personFactory.all[0]; }

trigger on PersonListModel.selectedPerson = newValue { detailPane.person = personFactory.all[newValue]; }

Page 22: Rich Internet Applications  con JavaFX e NetBeans

Arrays

var x = [1,2,3]; insert 12 into x; // yields [1,2,3,12] insert 10 as first into x; // yields [10,1,2,3,12] insert [99,100] as last into x; // yields [10,1,2,3,12,99,100]

var x = [1,2,3]; insert 10 after x[. == 10]; // yields [1,2,3,10] insert 12 before x[1]; // yields [1,12,2,3,10] insert 13 after x[. == 2]; // yields [1, 12, 2, 13, 3, 10];

var x = [1,2,3]; insert 10 into x; // yields [1,2,3,10] insert 12 before x[1]; // yields [1,12,2,3,10] delete x[. == 12]; // yields [1,2,3,10] delete x[. >= 3]; // yields [1,2] insert 5 after x[. == 1]; // yields [1,5,2]; insert 13 as first into x; // yields [13, 1, 5, 2]; delete x; // yields []

Page 23: Rich Internet Applications  con JavaFX e NetBeans

ListBox

• Model• Selected object(s)• Cell configuration

Page 24: Rich Internet Applications  con JavaFX e NetBeans

Canvas, Group

• Canvas allows to mix components with graphics

• Group is the glue between Canvas and complex structures

Page 25: Rich Internet Applications  con JavaFX e NetBeans

ListBox example

ListBox { layoutOrientation: VERTICAL selection: bind personListModel.selectedPerson cells: bind foreach (person in personListModel.personFactory.all) ListCell { text: "{person.firstName} {person.secondName}" } }

Page 26: Rich Internet Applications  con JavaFX e NetBeans

Search (array query)

• “List comprehensions”– Create a list out of another list– With criteria (e.g. filtering)–

• select n*n from n in [1..100]

Page 27: Rich Internet Applications  con JavaFX e NetBeans

Search (array query)

select indexof track + 1 from album in albums, track in album.tracks where track == album.title;

function factors(n) { return select i from i in [1..n/2] where n % i == 0; }

Page 28: Rich Internet Applications  con JavaFX e NetBeans

In our case

TextField { value: "Search" onChange: operation (string: String) { personListModel.selectedPerson = (select indexof person from person in personListModel.personFactory.all where person.secondName == string)[0]; } }

Page 29: Rich Internet Applications  con JavaFX e NetBeans

Talking to other tiers

• JavaFX uses the Java Runtime...• ... you can use whatever you need

– RMI, Spring Remoting, SOAP, Corba...

• Only pay attention to the footprint– What will be in the “Customer JRE”?

Page 30: Rich Internet Applications  con JavaFX e NetBeans

JFXBuilder

• See a few samples

Page 31: Rich Internet Applications  con JavaFX e NetBeans

Question Time

• ... and feedback too

What do you think about JavaFX?