35
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Introduction to JavaFX on Raspberry Pi Bruno Borges Oracle Product Manager for Latin America Java Evangelist bit.ly/javafxraspberrypij1

Introduction to JavaFX on Raspberry Pi

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Introduction to JavaFX on Raspberry PiBruno BorgesOracle Product Manager for Latin AmericaJava Evangelist

bit.ly/javafxraspberrypij1

Page 2: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 132

Bruno Borges

Oracle Product Manager / Evangelist

Developer, Gamer, Beer lover

JavaFX / Embedded Enthusiast

Twitter: @brunoborges

Page 3: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

What do you need to build JavaFX apps?

JavaFX Scene Builder● Linux supported!

Java SE 6/7/8● SE 8 comes with JavaFX libs as part of JRE

NetBeans 7.3.1+

Some things, and coffee

Page 4: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

JavaFX Scene Builder 1.1 GAbit.ly/javafxdownload

Page 5: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Raspberry Pi Configurationsfor JavaFX applications

CPU Overclock900~950MHz

Memory split128MB for video

Framebufferframebuffer_width=1280framebuffer_height=720

Page 6: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

CPU Overclockfor JavaFX applications

$ cat /proc/cpuinfoProcessor : ARMv6-compatible processor rev 7 (v6l)BogoMIPS : 697.95…$ sudo raspi-config

bit.ly/raspioverclock

Page 7: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

CPU Overclockfor JavaFX applications

$ cat /proc/cpuinfoProcessor : ARMv6-compatible processor rev 7 (v6l)BogoMIPS : 697.95…$ sudo raspi-config

Page 8: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

CPU Overclockfor JavaFX applications

$ cat /proc/cpuinfoProcessor : ARMv6-compatible processor rev 7 (v6l)BogoMIPS : 697.95…$ sudo raspi-config

Page 9: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Memory Splitfor JavaFX applications

128mb best performance

64mb may work

$ sudo raspi-config

Page 10: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Memory Splitfor JavaFX applications

128mb best performance

64mb may work

$ sudo raspi-config

Page 11: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Video Framebufferfor JavaFX applications

Edit /boot/config.txt

Enable (uncomment) these options, with these values:

framebuffer_width=1280framebuffer_height=720

Page 12: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Exiting a JavaFX Application on Raspberry.Pi

Connect over SSH and kill the java process

$ killall -9 java

Enable the debug environment variable to enable control-C exit command

$ export JAVA_DEBUG=1$ java -cp Stopwatch.jar stopwatch.MainScreen

Page 13: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Final parameters for JavaFX on Raspy

Do not show virtual keyboard (optional)-Dcom.sun.javafx.isEmbedded=false

Send video to the framebuffer (required!)-Djavafx.platform=eglfb

Page 14: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Building Your 1st JavaFX App

Page 15: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1315

Your First JavaFX App for RaspberryPi

Page 16: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1316

Your First JavaFX App for RaspberryPipublic class MyApplication extends Application {

@Override public void start(Stage stage) throws Exception { URL fxml = getClass().getResource("MyApplication.fxml"); Parent root = FXMLLoader.load(fxml); Scene scene = new Scene(root); stage.setScene(scene); stage.setFullScreen(true); // for Desktop. Not need for Pi stage.show(); }

public static void main(String[] args) { launch(args); }

}

Page 17: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1317

Properties

// JavaFXDoubleProperty value = new SimpleDoubleProperty(0);

public double getValue() { return value.get();}

public void setValue(double newValue){ value.set(newValue);}

public DoubleProperty valueProperty() { return value;}

Page 18: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1318

Properties

// JavaFXDoubleProperty value = new SimpleDoubleProperty(0);

public double getValue() { return value.get();}

public void setValue(double newValue){ value.set(newValue);}

public DoubleProperty valueProperty() { return value;}

Page 19: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1319

Bindings

Binding unidirecional● bind();

Binding bi-direcional● bindBidirectional();

Page 20: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1320

Bindings

Binding unidirecional● bind();

Binding bi-direcional● bindBidirectional();

Page 21: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1321

Bindings

@FXMLprivate Label humidityLabel;

...

// HUMIDITY MONITORHumidityMonitor humidityMon = new HumidityMonitor(...); humidityLabel.textProperty().bind(humidityMon.valueProperty());humidityMonitor.start();

Page 22: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1322

Bindings

IntegerProperty number1 = new SimpleIntegerProperty(1);IntegerProperty number2 = new SimpleIntegerProperty(2);DoubleProperty number3 = new SimpleDoubleProperty(0.5);

NumberBinding sum1 = number1.add(number2);NumberBinding result1 = number1 .add(number2) .multiply(number3);

NumberBinding sum2 = Bindings.add(number1, number2);NumberBinding result2 = Bindings .add(number1, multiply(number2, number3));

Page 23: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1323

JAX-RS 2.0 Client API

Download libs from here:

bit.ly/jersey-libs-javafx

https://jersey.java.net/

Page 24: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1324

JAX-RS 2.0 Client API

import javax.ws.rs.client.Client;import javax.ws.rs.client.ClientBuilder;...Client client = ClientBuilder.newClient();

Page 25: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1325

JAX-RS 2.0 Client API

String uriTemplate = "http://{host}:{port}/things";

String host = System.getProperty( "things.host", "192.168.1.101");

String port = System.getProperty( "things.port", "8080");

Page 26: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1326

JAX-RS 2.0 Client API

Map<String, Object> params = new HashMap<>();params.put("host", host);params.put("port", port);

UriBuilder uriBuilder = UriBuilder.fromUri(uriTemplate);

Client thingsServerURI = uriBuilder.buildFromMap(params);

Page 27: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1327

JAX-RS 2.0 Client APIUsing the things REST client

String sHumidity = thingsServerURI.path("/humidity").request().get(String.class);

Page 28: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1328

Working with ThreadsUsing the things REST client with threads

class MonitorService extends TimerTask { public void run() { String sval = thingsHumidyPath

.request().get(String.class); final float humidity = new Float(sval); Platform.runLater(new Runnable() { @Override public void run() { floatValue.set(humidity); value.set(Float.toString(humidity)); } }); } }

Page 29: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1329

Working with ThreadsUsing the things REST client with threads

class MonitorService extends TimerTask { public void run() { String sval = thingsHumidyPath

.request().get(String.class); final float humidity = new Float(sval); Platform.runLater(new Runnable() { @Override public void run() { this.floatValue.set(humidity); this.value.set(Float.toString(humidity)); } }); } }

Page 30: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1330

Back to the Bindings

@FXMLprivate Label humidityLabel;

...

// HUMIDITY MONITORHumidityMonitor humidityMon = new HumidityMonitor(...); humidityLabel.textProperty().bind(humidityMon.valueProperty());humidityMonitor.start();

Page 31: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1331

Working with ThreadsUsing the things REST client with threads

Start the Monitoring service

Timer timer = new Timer(true);timer.schedule(new MonitorService(), 0, DELAY);

Page 32: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

QUESTIONS?

Page 33: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 1333

Thanks!

@brunoborges

Page 34: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

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.

Page 35: Introduction to JavaFX on Raspberry Pi

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.