Creating a package Creating inheritance in the browser To create inheritance using the browser: 1. Right-click a class and then select Add New > SuperClass . The Add Superclass window opens. 2. Use the list to specify the superclass. 3. Click OK . Inheriting from an external class To inherit from a class that is not part of the model, set the CG::Class::UseAsExternal property for the superclass to Checked . This prevents code from being generated for the superclass. To generate an #include of the superclass header file in the subclass, do one of the following actions: Љ Add the external element to the scope of some component. Љ Map the external element to a file in the component.
Љ Set the CG::Class::FileName property for the superclass to the name of its specification file (for example, super.h ). That file is included in the source files for classes that have relations to it. If the FileName property is not set, no #include is generated. Another way to inherit from an external class is to exclude the external class from the code generation scope. For example, if you want a class to extend the Java class javax.swing.JTree without actually importing it: 1. Draw a package javax . 2. Draw a nested package swing inside javax . 3. Draw a class JTree inside the swing package. 4.
Exclude the javax package from the component (do not make it one of the selected elements in the browser). This prevents the component from generating code for anything in the javax package. This gives the rest of the model the ability to reference the JTree class without generating code for it. In this way, a class in the model (for example, MyJTree) can inherit from javax.swing.JTree . If the subclass is public, the generated code is as follows: import javax.swing.JTree; ... public class MyJTree extends JTree { ... } Rational Rhapsody 549