I have a main controller class that shows a JFrame containing a JTable and, for each row in this table, I have to show a specific “form” on doubleclick.
This secondary window will need information about the specific row selected on the main JTable, as well as some objects saved as fields in the controller class.
An conceptual example of what I need to do is the following:
I have a set of Shops (listed in the JTable in the main JFrame) and, on double click on a row, another window has to appear, allowing for a management of the Shop (sending orders, checking deliveries, etc…).
My question, me being such a newbie with Swing, is: what is the best organization for a common pattern like this one?
Should I model another JFrame and pass as arguments all the data that I could happen to need (I really don’t like this), or should I pass only a reference to the Controller class (this would be against the MVC pattern, I think).
Or maybe I should use a JDialog instead of another JFrame? The thing is that, really, the functionality that I need from this second window are a little too big for a dialog, I think…
I am confused, any tip/suggestion/advice will be much appreciated!
Thank you
Regards
I actually don’t like the idea of having a listener inside my Model class (aka Shop) – implementing the
ActionListener. I think I would extend theJDialogclass (let’s call itMyJDialog) then when a row is double clicked … create a new instance ofMyJDialogclass and pass in theShopobject in the constructor. Within theMyJDialogclass you can modify the Shop object by calling mutators (setters). Moreover, theShopclass should have a way of notifying observers when a property is changed – take a look at PropertyChangeSupport.