This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi all, After having (nearly) completed the backend, i am working at the GUI now, and altready have a working version using the MVC architecture :-)
For invoking actions on the Controller, I see the following possibilities:
Method 1. To every control in the View an anonymous ActionListener is added using addActionListener in the following well-known way.
This is straight-on and works of course fine. But when we want to attach the action to more than one gui control, for example menu-items, it is better to use Actions (javax.swing.Action) to define caption, tooltip, and the actions performed in a uniform way. This brings us to method 2.
Method 2. For each action, a separated CustomAction class is defined, extending the AbstractAction class. For example: class BookFlightsAction extends AbstractAction. The various propeties can be set in the constructor, and the actions in the implemented actionPerformed method. I create those actions in the contructor of the Controller class and add a method to the Controller for each action: public Action getCustomAction();
The action is attached to the control as follows: button.addAction(guiController.getBookFlightsAction());
The PROBLEM is that no parameters can be passed in as the action is created in the contructor of the Controller. I have solved this issue by passing in the JTable itself to the contstructor of the Controller, where the selected records can be retrieved using the getSelectedRecords() method. But this makes the Controller dependent of the JTable component, which is no good design I think. I introduced more abstraction by having the GUI implement an interface containing methods that return the desired info from the JTable. I pass this interface in to the Controller constructor instead of the JTable itself. Is this a well known way of doing ? Or are there other ways I haven't thought of yet... ?
Regards, Klaas [ July 31, 2004: Message edited by: Klaas van Gelder ]
"What you don't know, can't help you"
SCJP (81%), SCWCD (81%), SCJD (354/400), SCBCD (85%)