|
This extension basically adds a TutorialTo add CookBSFLib.setupTags (CookSwing.getSwingTagLibrary ()); The type of the object this tag creates depends on the script. Script can be inserted in two ways: inside the tag, or in another file/resource specified using "src" attribute. <button text="Button 1"> <script language="beanshell" func="addActionListener"> import java.awt.event.ActionListener; actionPerformed( e ) { bsf.lookupBean ("statusBar").setText (e.getSource ().getText () + " Pressed"); } return (ActionListener)this; </script> </button> <button text="Button 2"> <!-- calling an external script code (identical to the script above) --> <script func="addActionListener" src="examples/cookbsh/action.bsh"/> </button> The language of the script can be determined in two ways, either by explicitly setting
the For languages that cannot return a variable at end of the script (e.g. Jython), the
<button text="Button 1"> <script language="jython" return="action" func="addActionListener"> from java.awt.event import ActionListener class ExitAction (ActionListener): def actionPerformed(self, e): bsf.lookupBean ("statusBar").setText (e.getSource ().getText () + " Pressed"); bsf.registerBean ("action", ExitAction ()); </script> </button> <button text="Button 2"> <!-- calling an external script code (identical to the script above) --> <script src="examples/cookbsf/action.py" return="action" func="addActionListener"/> </button> DemoTry the Java Web Start demo for some simple demos. The frame code was also written in BSF using BeanShell. Note: BSF 2.3.0 has an uncaught exception in BSFManager class initializer code if it is run within Java Web Start sandbox. See ASF Bugzilla for more information. This demo used the changes mentioned in the bug report to get Java Web Start working. |