Java Reference
In-Depth Information
4.3.2
Constructing the view
We now describe how to construct the GUI. Figure 4.2 shows the structure. We
take a frame with border layout. The class is called
TextAnalysisFrame
and is
derived from
SimpleFrame
.Atthe bottom (South) we 'glue' a
JButton
into the
frame. In the middle (centre) we glue a panel of type
TextAnalysisPanel
. This
panel is defined to take the text components. It has a 3
2 grid layout. The grid
contains - in this order - a label, a text field and four more labels. The components
are coloured to make them easier to distinguish and the gap between rows and
columns is increased. Through these gaps we can see the yellow background of
the panel.
Other ways of constructing the GUI are possible. One could use another panel
that contains the 'Analyse' button and the text analysis panel. In this case the
listener should be instantiated in the new panel.
To achieve the desired functionality, we define the method
startAnalysisAnd-
DisplayResult
in
TextAnalysisPanel
. This method reads the text from text field
inputField
and passes it to the text analysis model by calling method
analyse
of
TextAnalysisModel
. The panel itself does not know how the text is analysed. The
×
JTextField
D
a
n
n
e
b
r
o
g
D
A
N
N
E
B
R
O
G
JFrame
JPanel
E
n
t
e
r
t
e
x
t
:
C
u
r
r
e
n
t
t
e
x
t
:
1
N
o
o
f
E
s
i
n
c
u
r
r
e
n
t
t
e
x
t
:
JLabel
A
n
a
l
y
s
e
JButton
Figure 4.2 The blueprint for our GUI
Search WWH ::
Custom Search