next up previous contents index
Next: Using inheritance Up: ClassesComponents, and Previous: Base classes

Writing classes

We can define our own classes. Let us reconsider the HelloWorld example. We can write a separate class for all "Hello World!" buttons and have a component of the class placed in the main panel.

       main class HelloWorld {
            component HelloWorldButton hw;     
       }
       class HelloWorldButton {
            component Button bt{text=="Hello World!"};
       }
The class HelloWorldButton defines a sub-panel.

Sub-panels have all the following attributes that can be used without definition: my_x, my_y, my_width, my_height, and my_color. They denote the xy-coordinates of the left-upper corner, the size, and the color of the sub-panel. Redefining these attributes will cause a compilation error. A sub-panel is invisible by default, but can be shown when it is given a different color from its container, i.e., the sub-panel or main panel in which the sub-panel is placed.

We use only one global coordinate system. Even when we use xy-coordinates in sub-panels, we mean the coordinates in the global coordinate system.

Unlike in Java classes, DJ classes do not have constructors. When an instance of a DJ class is generated, its attribute values are all determined by the system.  



Neng-Fa ZHOU
Sat Apr 18 16:14:29 JST 1998