Showing posts with label JavaFX. Show all posts
Showing posts with label JavaFX. Show all posts

Saturday, October 3, 2015

Sunday, August 3, 2014

Run JavaFX application on Raspberry Pi remotely from Netbeans 8

With Remote Platform set up on Netbeans 8, we can also develop JavaFX application on host computer running Netbeans, run the application remotely on Raspberry Pi. In case of Java FX application running on Raspberry Pi, it will display on Raspberry Pi monitor, instead of console.

Thursday, March 27, 2014

Getting Started with JavaFX Embedded on a Raspberry Pi

Learn how to quickly get a JavaFX simple application up and running on a Raspberry Pi development board.

Saturday, December 7, 2013

JavaFX animation on raspberry Pi

The exercise draw animation on Raspberry Pi base on user input. What it can do:
  • Load image from internet
  • Detect mouse action to draw the path
  • The image will run following the path

Please note that the JavaFX code have not handle the exit case. So if you run on local console, you cannot exit the program.

The program is developed on Windows 8 with Netbeans. The original Java code is copied from Java-Buddy. Modified as:
package javafx_path;

import javafx.animation.PathTransition;
import javafx.animation.PathTransitionBuilder;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 *
 * @org java-buddy.blogspot.com
 * @web helloraspberrypi.blogspot.com
 */
public class JavaFX_Path extends Application {

    PathTransition pathTransition;

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("java-buddy.blogspot.com");
        Group root = new Group();
        Scene scene = new Scene(root, 800, 600, Color.WHITE);

        //load image from internet
        final Image image1 = new Image("http://goo.gl/kYEQl");
        
        final ImageView imageView = new ImageView();
        imageView.setImage(image1);

        final Path path = new Path();
        path.setStrokeWidth(1);
        path.setStroke(Color.BLACK);

        //Mouse button pressed 
        //- clear path and start from the current X, Y.
        scene.onMousePressedProperty().set(
                new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                path.getElements().clear();
                path.getElements().add(
                        new MoveTo(event.getX(), event.getY()));
            }
        });

        //Mouse dragged - add current point.
        scene.onMouseDraggedProperty().set(
                new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                path.getElements().add(
                        new LineTo(event.getX(), event.getY()));
            }
        });

        //Mouse button released,  finish path.
        scene.onMouseReleasedProperty().set(
                new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                pathTransition = PathTransitionBuilder.create()
                        .node(imageView)
                        .path(path)
                        .duration(Duration.millis(5000))
                        .orientation(PathTransition.OrientationType
                                .ORTHOGONAL_TO_TANGENT)
                        .cycleCount(1)
                        .build();

                pathTransition.play();
            }
        });

        root.getChildren().add(imageView);
        root.getChildren().add(path);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

}

Copy the generated jar,JavaFX_Path.jar, to Raspberry Pi. Then run it in text console by enter:
$ java -jar JavaFX_Path.jar



Related:
- Run JavaFX on Raspberry Pi

Tuesday, December 3, 2013

Run JavaFX on Raspberry Pi

This post try to develope JavaFX Application on Windows 8 and run on Raspberry Pi.

Development host PC: 
OS - Windows 8 Pro
Development Tools: NetBeans IDE 7.4
JDK: jdk 1.7.0_45

Raspberry Pi:
Model B with 8G SD Card
OS: Raspbian wheezy 2013-09-25
Memory Split: 64
Overclock: Medium 900MHz
Run in Text Console mode
java version 1.8.0-ea (build 1.8.0-ea-b117)

Steps:
- New a JavaFX Application in Netbeans, named "JavaFXHelloPi".

- Modify the Java code to add a button to exit.
package javafxhellopi;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class JavaFXHelloPi extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });

        Button btnExit = new Button();
        btnExit.setText("Exit");
        btnExit.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Platform.exit();
            }
        });

        VBox vBox = new VBox();
        vBox.getChildren().addAll(btn, btnExit);

        StackPane root = new StackPane();
        root.getChildren().add(vBox);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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


- It run on Windows 8 like this:

- ftp the created jar, JavaFXHelloPi\dist\JavaFXHelloPi.jar, to Raspberry Pi.

- ssh to Raspberry Pi, run the jar by entering the command:
$ java -jar JavaFXHelloPi.jar



Remark:
It's just a personal experiment. For official steps, refer: https://wiki.openjdk.java.net/display/OpenJFX/OpenJFX+on+the+Raspberry+Pi

More example of JavaFX on Pi:
JavaFX animation on raspberry Pi

Sunday, October 13, 2013

JavaFX on Raspberry Pi

Intro to JavaFX on Raspberry Pi - Part I
Bruno Borges (@brunoborges on Twitter) introduced JavaFX on Raspberry Pi at Java Embedded Challenge for Raspberry during JavaOne 2013.


Intro to JavaFX on Raspberry Pi - Part II
Bruno Borges (@brunoborges on Twitter) introduced JavaFX on Raspberry Pi at Java Embedded Challenge for Raspberry during JavaOne 2013.