Introduction | Your first interface | Building a model | Advanced features | Resources

2.4 Adding actions to the interface

In this step, you will see how the functionality of an interface can be further increased by adding action buttons to perform specific tasks.

When a model is designed, as well as providing variables that the Interface Builder can access, the model programmer can also write actions that are preformed on the variables, and make these available too. You can see what actions are available in a model from the Action menu. The Ohm's Law model has two actions - Low Resistance and High Resistance.

If you select one of these options, the action will be performed (in this case setting the value of resistance either high or low). This is fine when you are working within the Interface Builder, but how do you make these actions available to the end user when you produce the final applet? The answer is that you can attach an action to an Action Button on the interface, so that the action will be performed when a user presses the button.

If you select the Object menu, then Button and finally Action Button, when you move your cursor over the interface it will become a crosshair, which when clicked will add an action button to the interface.

When you've placed an action button on the interface, you can change the actionNumber property to the name of the action you want the button to perform (all possible actions will be available from a drop-down list).

Place two action buttons on your interface, make one perform the High Resistance action and one the Low Resistance action. Try running the interface and see what effects pressing these buttons have on the other objects on the interface.

When you've placed the two buttons on your interface, it will look something like this:

Now all the functionality of your interface is complete. In the next step you will discover how to improve the appearance of your simulation using text, graphical objects and images.