import java.awt.*; import java.awt.event.*; /** * Instantiates the model, GUI view, and the event listeners (i.e. controllers). * Note the use of anonymous classes for event listeners. * @author Dung X. Nguyen * @author Robert "Corky" Cartwright. * @since Oct. 08, 1999 */ public class FLControl { /** * The view * @SBGen Variable (,view,,64) */ private FLGUI gui = new FLGUI (); /** * The list model. * @SBGen Variable (,model,controller,64) */ private FunList list = Empty.only; // NOTE use of Singleton! /** * Initializes the model and the associated view. Registers event listeners with the view as anonymous inner classes. */ public FLControl() { gui.updateView (list); // Add anonymous ActionListener class to handle the Empty button click: gui.addEmptyListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { list = Empty.only; gui.updateView (list); } } ); // Add anonymous ActionListener class to handle the Cons button click: gui.addConsListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { String input = gui.getInput(); try { int i = Integer.parseInt(input); list = new Cons (new Integer (i), list); gui.updateView (list); } catch (NumberFormatException x) { // For debugging and illustration purpose: System.out.println ("ConsListener.actionPerformed: input " + input + " is not a number!"); } } } ); // Add anonymous ActionListener class to handle the Sum button click: gui.addSumListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { Integer sumInt = (Integer)list.execute (Sum.only); gui.setOutput(sumInt.toString()); } } ); // Add anonymous ActionListener class to handle the GetNth button click: gui.addGetNthListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { int n = Integer.parseInt(gui.getInput()); Integer nthInt = (Integer)list.execute(new GetNth(n)); gui.setOutput(nthInt.toString()); } } ); } /*** * Entry point into the program * @param args The parameters for the entry. They are not used here. */ public static void main(String[] args) { new FLControl(); } }