Wednesday, March 09, 2022

Installing jGRASP in Linux

First download and unzip jGRASP for Linux (the bundled version).

Unzip it in a directory, in this case it was downloaded inside the directory "snap". Then create a link to it in /usr/bin/jgrasp as follows:

 sudo  ln  -s  /home/username/snap/jgrasp/bin/jgrasp  /usr/bin/jgrasp

You can call the program from command line or you can also create a desktop icon to call its execution.

Adding support for JavaFX:

First download the JavaFX and unzip it in a proper location, it could be also inside the "snap" directory. Then you need to go in jGRASP to "Settings ==> Compiler Settings ==> Workspace", a new window will be opened, and go to the "JavaFX" tab, there browse and input the JavaFX home path.


Note: the JavaFX has to be of the proper architecture, i.e. x64, or any other correctly corresponding to your machine, otherwise graphics won't work. 


After that, for testing purposes you can use the following code from Oracle.

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
 
public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        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!");
            }
        });
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    }
}

The outcome will be the following:


Every time the button is clicked you will get the string:

Hello World!

That string is in the terminal in pure text mode.





---