Graphical User Interfaces > Example Graphical User Interface > Creating the Code for the Model

Creating the Code for the Model
In the demo folder under the COMSOL Multiphysics installation directory there are some files that can be used for creating the demonstration example. The example models for this demonstration is placed in the demo\api\beammodel directory. There is a model file called BeamModel.mph. This file contains the model to use for the GUI. Open COMSOL and open the model.
Spend some time familiarizing yourself with the model. Note especially that the model has a set of parameters under Global Definitions that are used to update the dimensions of the geometry, and that there is a set of variables defined under Model>Defintions>Variables that are used to define the outputs from the simulations.
Although any parameter or setting in the model can be changed using the COMSOL API it is recommended that input and output data are well defined as shown in this model. Such definitions make it easier to follow the data flow in the model.
You can export a model file for Java from the COMSOL Desktop. Before exporting, it is worthwhile to make the model history compact. Doing so makes sure that the exported Java file only contains the necessary steps that are needed to reproduce the model.
Use Compact History to make the model history compact. Then save the Java file using Save As. Choose Model file for Java (*.java) from the Save as type list, and name the file BeamModel.java. Then click Save.
Compacting the History and Creating a Copy Using Save As in the COMSOL Multiphysics Reference Manual