Hello i would like to have opinion on the way i design my application. The main frame of the application is containing a JList. Via a JDialog i create new Database object that are displayed in the JList as they are created. I update the model of the JList using the pattern observer. The model implements an observer interface and the Database implements subject interface. Each time i create a Database object i update the model with addElement(database). Is this a good way of doing in swing or there are better one ? Thank you.
It's common to build a Controller class that is separate from the UI and isn't a Swing component at all. When the user updates a value the View (Swing screen or widget) notifies the Controller. The Controller updates the Model (not the little model inside the Swing control, but a Business Model layer in the application). The observable Model publishes a change event, and other observer widgets on the View listen for that.
Google for MVC and make sure you're reading about fat-client MVC, not web style MVC 2. Let us know what questions all that raises.
This gets a little confusing because Swing has "model" objects and actually has a tiny little MVC architecture going on inside its widgets. For this conversation because you mentioned "database" I'm trying to ignore the little MVC inside Swing and think about a larger application design.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Alright, i m reading this tutorial which is quite clear, but should i have different controller for different object of the model or different ui component, or just one controller for the whole application ?
Hello, i m really having trouble to understand and implements the mvc pattern in my application. If someone could help me to define the view, the controler and the model and how they can interact each other. So i have Database object that are created through a popup. When i click on a button after filling details of the database, the Database object is instanciated, the popup is not visible and a JList on the main panel is updated with the new database created. The JList model (extends DefaultListModel) contains the list of database objects. Thanks for help.
I am sorry for upping old thread, but i try to implement also MVC pattern in my Swing app. So i made simple examples which should follow simple rules, like all are independent.
Controller and View. As you can see the controller is inner class which you can make as separate class also you can add sub-controllers, like you got there 5 buttons and all are doing something difficult, you can actually make sub-controllers for that.
One thing what i think should be done a bit differently. View should be class which extends from JPanel and then make the Application creation class where you add view. What you think ?
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop