在“ .bsh”脚本中从ActionListener调用“ .bsh”脚本

时间:2019-04-12 23:02:03

标签: java scripting beanshell

我编写了一个bean脚本(.bsh文件),以在单击按钮时调用另一个bean脚本。

从代码主体调用bean脚本时,代码运行良好,但是从按钮的动作侦听器中调用时,崩溃。

代码如下:

//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");

我是Java / Beanshell新手,正尝试使用文档来弄清楚这个问题,但似乎无法弄清楚。关于如何解决这个问题/是否做得更好的任何想法?谢谢!

0 个答案:

没有答案