Java widget for scripting with jshell.
Requires Java 9 or later, as it relies on the
jshell executable in Java's
The widget comes in form of a panel with two parts, the scripting part for your code
(including syntax highlighting thanks to RSyntaxTextArea)
and the output part, which will receive any output generated by
With this widget you can write Java code without having to compile it,
takes care of that.
You only have to place the
JShellPanel in a frame or dialog and you
can start scripting.
import javax.swing.JFrame; import com.github.fracpete.jshell.JShellPanel; ... JShellPanel panel = new JShellPanel(); JFrame frame = new JFrame("JShell"); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.setSize(1200, 900); frame.setDefaultCloseOperation(BaseFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true);
It is also possible to listen to events in the widget, by supplying a
com.github.fracpete.jshell.event.JShellListener object. The following code
simply outputs the event type to stdout:
import com.github.fracpete.jshell.event.JShellEvent; import com.github.fracpete.jshell.event.JShellListener; import com.github.fracpete.jshell.JShellPanel; ... JShellPanel panel = new JShellPanel(); panel.addJShellListener((JShellEvent e) -> System.out.println(e.getType()));
You don't have to use the widget in your own code, you can simply go ahead and do some scripting. Here is what you need to do:
download a release zip file and unzip it
place any additional jars that you want to use for coding in the
start up the user interface with the appropriate script:
Add the following dependency to your
<dependency> <groupId>com.github.fracpete</groupId> <artifactId>jshell-scripting</artifactId> <version>0.0.2</version> </dependency>