Skip to content

Instantly share code, notes, and snippets.

@tomoTaka01
Created September 25, 2013 14:05
Show Gist options
  • Save tomoTaka01/6700138 to your computer and use it in GitHub Desktop.
Save tomoTaka01/6700138 to your computer and use it in GitHub Desktop.
The temperature application using JavaFX and RaspberryPi.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
/**
*
* @author tomo
*/
public class RaspberryPi extends Application {
@Override
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());
}
});
primaryStage.setTitle("Hello Raspberry Pi!");
root.getChildren().addAll(temperatureLable,temperatureText, button);
primaryStage.setScene(new Scene(root, 500, 100));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment