I wrote a beanshell script (.bsh file) to call another beanshell script when a button is clicked.
The code runs fine when the beanshell script is called from the main body of the code, but crashes when called from within the button's Action Listener.
Here is the code:
//Creating and displaying the button
JFrame f2=new JFrame("exampleFrame");
JButton acquireButton = new JButton();
acquireButton.text = "Acquire";
f2.setSize(100,100);
f2.add(acquireButton);
f2.setVisible(true);
//Action Listener for the Button
acquireButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
print("Acquire Clicked"); //This prints when button is clicked
//CRASHES WHEN CALLED FROM HERE
//source("C:\\Users....\\Script I Want to Call.bsh");
f2.setVisible(false); //Removes button once it is clicked
f2.dispose();
return;
}
});
//WORKS WHEN CALLED FROM HERE
//source("C:\\Users....\\Script I Want to Call.bsh");
I'm a Java/Beanshell newbie trying to figure it out using the documentation, but can't seem to figure this one out. Any ideas on how to fix this/do it better? Thanks!