Java in Brainstorm

Authors: Martin Cousineau, Raymundo Cassani

Java is a multi-platform and object-oriented programming language. Matlab supports its execution in order to facilitate writing more complex graphical user interfaces and applications.

Java version

You have to keep in mind that not every Matlab versions ship with the same version of the Java Virtual Machine (JVM). See this Wikipedia page for specific JVM versions for each release of Matlab. With the general objective of supporting older Matlab versions (2008 to today), we need therefore to support Java 6 to 8.

Java repository (bst-java)

For the GUI elements Brainstorm uses a compiled .jar file (brainstorm.jar). This .jar is included in the binary Brainstorm distribution of Brainstorm. For the source version of Brainstorm (executed from Matlab) the .jar is automatically downloaded. As the raw Java code is not of use to regular users.

To access to the raw Java code used by Brainstorm, refer to this GitHub repository:
https://github.com/brainstorm-tools/bst-java

The repo also includes the project files to open the repository as a project in the popular Java IDE NetBeans which we recommend for writing and testing your Java code.

The brainstorm java project is compiled with the Java SE Development Kit 7, Update 80 aka JDK 7u80 which can be obtained in:
https://www.oracle.com/java/technologies/javase/javase7-archive-downloads.html

Once JDK7u80 is installed, add it as platform in NetBeans:
Tools > Java platforms > Add platform (JSE) : C:\Program Files\Java\jdk1.7.0_80

(!) The JSE platform must be defined for each project in:
Right-click on Project > Project properties > Libraries > Java Platform.

Pushing your changes to Matlab

Once you are satisfied with and tested your changes in your Java IDE, you need to push your changes to MATLAB.

Examples of changes to the brainstorm java project (new node types, icons, other GUI, etc.) can be found in the its commit history.

Calling Java functions in Matlab

Calling Java functions is extremely easy from Matlab, as documented here on the official Mathworks website.

Creating Java Swing elements for GUIs

To create Java objects for GUIs, Brainstorm already has wrappers in place to simplify and harmonize the process across the program. Refer to the gui_component() function to do this. Also, have a look at the CreatePanel() function of any panel_ file to see examples of creating Swing GUI elements in Matlab.

Java (last edited 2024-02-23 14:13:02 by RaymundoCassani)