The script file contains functions and global variables (holding state info), and also creates the JDialog box with components (JButton). The button has a listener, but I am unable to reference the global variables and functions.
- Code: Select all
/* Short Example, assume the JavaImporter has the write java classes*/
var _myVariable = 12;
function _myFunction(){ return true;}
function doFunction(){
var panel = new JPanel();
var dialog = new Dialog();
dialog.setConentPane(panel);
var btnSubmit = new JButton("submit");
panel.add(btnSubmit);
btnSubmit.addActionListener( new ActionListener(){
actionPerformed: function(e){
if( _myFunction() ){ /* <-- breaks here */
_myVariable += 1; /* <-- breaks here */
}
}
});
}
doFunction();
This would run under Javascript Nashorn, but in Rhino it errors out because _myFunction and _myVariable are undefined.
I tried to extend the ActionListener so I could pass in the global object, but examining the global object, it looks like I won't get any state info, only the script code.
Any Ideas how to access the globals?