9.3.1 Controller Implementation

For the controller functionality of the ViewerController component, a number of buttons are added to the GUI window for starting, stopping and resetting the stopwatch. These correspond directly to the timerStart, timerStop and timerReset methods on the model's control interface. Since the control interface methods are thread safe, it is possible to call them directly from the context of the GUI thread using a standard Swing ActionListener object as shown in Figure 9.6.


\begin{listing}
% latex2html id marker 1981\begin{verbatim}...
// Populate ...
... });
...\end{verbatim}
\caption{Adding Control Buttons to the GUI}
\end{listing}

When connecting control buttons to the model control interface, an anonymous instantiation of the ActionListener class is specialised by the addition of the actionPerformed method, which simply invokes the required method on the model control interface. In this example the control interface is named appControl and is an instance of the ApplicationControl interface given in Listing 9.1.

There is also the `close' button on the window frame which corresponds to the timerQuit method on the control interface. Again, this may be called directly from the GUI thread using a standard Swing WindowAdapter object as shown in Listing 9.7.


\begin{listing}
% latex2html id marker 1995\begin{verbatim}...
// Create th...
...tim}
\caption{Adapting Window Controls to Model Control Interface}
\end{listing}