User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

tutorial:usejava [2015/12/28 01:38]
skylarmt Add java info
tutorial:usejava [2019/04/16 02:40]
Line 1: Line 1:
-====== Using Java from Scripts ====== 
-It's possible to use SyMAT code from scripts, as well as access Java classes. ​ This isn't a tutorial per se; rather, a working example program written in JavaScript. ​ It is intended as a starting point for writing plugins with their own user interfaces. 
-<WRAP center round info 60%> 
-SyMAT 2.1 has a Java interpreter included, so you can write pure Java code instead. 
-<file javascript scriptingjava.syjs>​ 
-function init() { 
- var frame = new JInternalFrame("​Test"​);​ 
- frame.setClosable(true);​ 
- frame.setLayout(null);​ 
- frame.setSize(300,​300);​ 
- var btn = new JButton("​Hi"​);​ 
- frame.add(btn);​ 
- btn.setLocation(5,​10);​ 
- btn.setSize(100,​30);​ 
- var btnaction = { actionPerformed:​ btnAction }; 
- btn.addActionListener(btnaction);​ 
- Main.loadFrame(frame);​ 
-function btnAction() { 
- notify("​Button pressed!"​);​ 
-This code first imports some Java classes, including SyMAT'​s main codebase. ​ In the init() function, we make a new JInternalFrame with the title "​Test",​ and set some properties. ​ Then we make a button and add it to the frame. ​ We set the button size and location. ​ Then we make a new ActionListener and add it to the button, so when the button is clicked the code inside btnAction() will run.  Then we access SyMAT'​s window layout function and tell it to display the frame we made.  The last line of the code calls the init() function, which makes things happen. 
tutorial/usejava.txt ยท Last modified: 2019/04/16 02:40 (external edit)