Let us consider the following example:
main class HelloWorld {
component Button bt{text=="Hello World!"}; //component declaration
}
This program has only one component declaration which declares that
the panel has a button named bt and the text on the button is
Hello World!. The statement in the brackets is called a constraint
that constrains the value of the text attribute of bt.
Nothing is said about the color and size of the button, the font of
the text, and the position of the button in the panel. we can but do
not have to give the values of these attributes. The system will
determine the attribute values for us either by using the constraints
we provided or by using the default values.
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 which itself is
unvisible. DJ retains the object-oriented feature of Java. By using
inheritance, we can also write the HelloWorldButton as follows:
class HelloWorldButton extends Button {
text=="Hello World!";
}