|
This extension basically adds a <bsh> tag, which supports BeanShell in CookXml. Each time this tag is used, a new instance of Interpreter is created. Objects created using XML can be referenced using their id. Personally I am not a big fan of scripting inside XML, since excessive use of scripts instead of actual Java code is meaningless in terms of developemental efforts and performance. However, from time to time I do find myself wishing to have extra flexibilities in designing certain aspects of GUI using XML. See the demo offered below to see what I mean. TutorialTo add CookBSHLib.setupTags (CookSwing.getSwingTagLibrary ()); The type of the object this tag creates depends on the beanshell code. BeanShell code can be inserted
in two ways: inside the tag, or in another file/resource specified using " <button text="Button 1"> <bsh func="addActionListener"> import java.awt.event.ActionListener; actionPerformed( e ) { statusBar.setText (e.getSource ().getText () + " Pressed"); } return (ActionListener)this; </bsh> </button> <button text="Button 2"> <!-- calling an external BSH code (identical to the bsh code above) --> <bsh func="addActionListener" src="examples/cookbsh/action.bsh"/> </button> DemoTry the Java Web Start demo for some simple demos. The frame code was also written in BeanShell. |