Java Reference
In-Depth Information
(a)
(b)
Figure 4.4 (a) A legal and (b) an illegal embedding structure. The illegal structure contains
a cycle consisting of components B, C and D. The arrow from component B to component
A means that B is embedded in A
The important rule to obey with hierarchical embeddings is that they have to
be cycle-free . This means that there is no cyclic embedding such as component A
into component B, and component B into component C and then component C
into component A. Formally, the embedding structure has to form a rooted tree ;
see also Figure 4.4. A cyclic embedding will result in a runtime error.
Exercises
4.1
Augment the text analysis application in two steps:
(1)
Add two more rows to the TextAnalysisPanel which display the num-
ber of all texts analysed so far and total number of 'E's seen in these texts.
The model supplies this information.
(2)
Add another button labelled 'Reset'. When this button is pushed the
total number of texts and the total number of 'E's seen are set to 0. This
also requires a change of the model part.
4.3
Construct a traffic light GUI. At the bottom there is a button. Clicking the
button makes the traffic light go to the next phase, i.e. 'red', 'red-yellow',
'green', 'yellow', and back to 'red'. Above, the current lights should be shown
as colours or text; see Figure 4.5.
RED
YELLOW
Figure 4.5 Sketch for the traffic light in Exercise 4.2
4.4
Design a GUI, with three buttons and one panel. The buttons are labelled
'red', 'blue' and 'yellow'. When clicking on a button the panel should show
the corresponding colour; see Figure 4.6.
Search WWH ::




Custom Search