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

3.4 Finishing the model

In this final step you will see how to complete the model code, compile it, and import the model into the Interface Builder.

When you have stepped through the thread support and custom objects screens, you will be able to view your generated code. The Wizard will look something like this:

The Wizard will create a java file: This files can be edited in the model wizard before finalising.

The wizard creates the file structure with variables and methods, but you still have to do the work of actually coding the model. If you look at the code in the top panel you will see method stubs for the methods you have specified in the Model Wizard. Remember that the change methods will be called when a change is made at the interface to the property that calls it, the methods that are registered as action methods will be accessible with action buttons at the interface.

To finish the ohmsLaw model, you will need to add code to the two change methods to re-calculate current(I) using the formula I = V / R. For the two action methods, you will need to set resistance (maximum 100, minimum 1) and re-calculate current. If you have any problems, you can see the completed code here:

When you have finished, click Finish to save your file (it will be saved in the place you specified in Step 1 of the Model Wizard - in this case a folder called training below the org/jelsim directory).

Although the model file can be edited in the Model Wizard, it is just a standard Java file, so for large models it is often easier to save it oncde the initial structure is defined and then edit it into your usual Java text editor.

If you now navigate to the training folder, you will see the file: You can compile the file using a Java compiler. Note: before your file will compile, you must include the JelSIM installation directory in your computer's CLASSPATH, so that the JeLSIM classes used by the code you've just created will be found at compilation time.

Once you have your class file, it is ready to be imported into the Interface Builder. If you open the Interface Builder, then open the File menu, and the Import sub-menu, you can select Import Model. (If the Interface Builder is on the same computer that the Model Wizard is running on, the model will automatically be available.)

When asked to select a model file to open, you can navigate to your org/jelsim/training directory and select the ohmsLaw.class file. You will then be asked for a name for your model in the toolbar and then told to restart the Interface Builder. When you restart, your model will be available from the File, New toolbar.

Note: if you get a message that the file is already available, go to the Menu tab of the Configuration Editor (View, Preferences) and click Add. The simulation you've just imported will be available to add from the drop-down menu.

Compile the Ohm's Law Java file and import it into the Interface Builder.

Congratulations! You've successfully created and imported your first model. You can update and recompile the model without having to re-import it into the Interface Builder, a restart will allow the updated model to be picked up. If you find at any point that your model won't load, it is most likely that there is an error in the property or action registration, and this is the first place to check.