Java Embedded Challenge for Raspberry Pi
This is the first time for me to be here JavaOne in SF. I jumped into the RaspberryPi challenge to do something without any skills about RaspberryPi.
Thanks to the this information(Introduction to JavaFX on Raspberry Pi) I finished a small application which shows the temperature.
- Screen 1
They already provided the raspberry Pi which measures the temperature.
What I did is download the jars from above slide(page 23) and implement the small amount codes.
code 1 shows how to get the temperature. That is it.
- code 1
private String getTemperature() { Client client = ClientBuilder.newClient(); String uriTemplate = "http://192.168.1.11:8080/things"; return client.target(uriTemplate).path("/humidity").request().get(String.class); }
- code 2
public void start(Stage primaryStage) { HBox root = new HBox(); root.setPadding(new Insets(10)); root.setSpacing(10); Label temperatureLable = new Label("温度:"); final Text temperatureText = new Text(); Button button = new Button("get temperature"); button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { temperatureText.setText(getTemperature()); // <-- when you click the button ,the temperature shows up } }); primaryStage.setTitle("Hello Raspberry Pi!"); root.getChildren().addAll(temperatureLable,temperatureText, button); primaryStage.setScene(new Scene(root, 500, 100)); primaryStage.show(); }
The whole code is here The temperature application using JavaFX and RaspberryPi. · GitHub
I am very impressed that they are so nice. They helped me a lot!!!
I had a wonderfull time joining this events!
Just keep coding....