Java Reference
In-Depth Information
54.
this
.add(numberTextLabel);
55.
this
.add(numberOfEsLabel);
56.
}
57.
58.
public void
startAnalysisAndDisplayResult()
59.
{
60.
String text = inputField.getText();
61.
analysisModel.analyse(text);
62.
lastTextLabel.setText(analysisModel.getCurrentText());
63.
int
noOfEs = analysisModel.getCurrentNumberOfEs();
64.
numberOfEsLabel.setText(Integer.toString(noOfEs));
65.
inputField.setText("");
66.
}
67.
68.
}
■
4.4
The control part
Class
TextAnalysisListener
implements the interface
ActionListener
.It
is required to implement method
actionPerformed
. Here
actionPerformed
calls the method
startAnalysisAndDisplayResult
of
TextAnalysisPanel
.To
this end the
TextAnalysisListener
has to know the
TextAnalysisPanel
. This
is achieved by passing (a reference) to
TextAnalysisPanel
in the constructor of
TextAnalysisListener
.
public
TextAnalysisListener(TextAnalysisPanel taPanel)
Class
TextAnalysisFrame
generates an instance of
TextAnalysisListener
and
assigns it to the button labelled 'Analyse'.
TextAnalysisListener taList =
new
TextAnalysisListener(taPanel);
analyseButton.addActionListener(taList);
Below are the listings of the class
TextAnalysisListener.java
and the driver
class
testanalysisTest.java
. Figure 4.3 shows the result.
Figure 4.3 The appearance of the text analysis GUI
Search WWH ::
Custom Search