Lotus BeanMachine Reference Guide

Writing your own code

There are times when you need to do more than what BeanMachine's basic properties and connections provide. If you know how to program in Java, you can write your own code using BeanMachine's Java window.
Start a new applet and add a Ticker Tape part. Select Java from the Window pull-down. This launches the Java window. Across the top, there is a toolbar that helps you create Java source code. There is also a drop-down list labeled Other Methods, which shows all the methods you've written so far.
Let's walk through writing a new method. Click on the New Method button and a new method template will be pasted into the window for you. Change the highlighted text
newMethod
to whatever you want to call this method, such as
myMethod
Now, position the cursor after the first brace ( { ), and then click the Paste Part button. Select a part from the applet, such as Ticker Tape1, and it will be pasted into your method wherever the cursor is. Notice that the space in the part name has been replaced with an underscore character, and that Ticker_Tape1 is highlighted. With Ticker_Tape1 still highlighted, click the Paste Property button and then select Set text. This pastes in a Java expression that will set the text property. Replace the highlighted text with the string you want to use, and then click the Save button on the editor window toolbar.
Now, to run your new method, you need to make a connection. All the methods you write in the Java window are listed as actions of the Applet itself. So, select the applet canvas, and connect the Applet1 started event to Applet1 MyMethod action.
(You can use any part and event you want to trigger the connection.) Test your applet and make sure it works. If you make any syntax errors, you'll see them in the Log window after you click the Run button.
Let's look at a scripting examples in the samples directory. First, open parameters.app
. This sample shows you how to write a Java method that processes the parameters passed in on the <applet> tag from HTML.
Now open the Java window and study the getHTMLParameters
method. It uses more advanced Java statements and calls getParameter
to get information from the HTML tags. You can set up the default values using the parameters property of the applet, and then you can change the behavior of your applet by simply changing your HTML file instead of rebuilding your whole applet.
If you really know Java, the Java window has some advanced features. The Other Methods list has three special entries: imports, implements, and declarations. Under imports, you can add any special Java packages that you need to compile your method. Under implements, you declare any interfaces that you want the applet to implement. Under declarations, you can add your own instance variables to the applet. Another trick you can try is defining two methods in one. This gives you more flexibility in the parameter names and the return type of the method.
