A component declaration in a class, which takes the following form, declares one or more graphical components that comprise the class:
component Type ComponentDeclarator, ..., ComponentDeclarator;where the Type must be either the name of a base class or a user-defined DJ class. A component declarator declares one component or an array of components of the Type. A component declarator for one single component is an identifier, optionally followed by a sequence of constraints embraced in {}:
Identifier [ConstraintBlock]where Identifier is the name of the component, and ConstraintBlock is a sequence of constraints in the form:
{Constraint; ...; Constraint}which constrains the values for the attributes of the related components. The declaration of component arrays will be described in the Arrays section.
Unlike variables in Java, components cannot be assigned a value. When a component is declared, a new object of the specified type is created, whose attributes values are to be determined by the system. There are no constructors available in DJ classes, and thus, it is not possible to create a component explicitly by calling the constructor in the class.
The following shows three examples:
component Rectangle rect1, rect2{size == rect1.size}; component Label hw{text == "Hello World!"}; component Button bt{text == "Button"; x = y};The first one declares two rectangles that have the same size; the second one declares a label whose text is "Hello World!"; and the third one declares a button whose x-y coordinates are the same.