2

I have to build a swing gui applying mvc pattern using the observer pattern. I understood how observer pattern works but I don't know how to implement mvc pattern using observer patter.could someone help me to understand maybe posting a sample piece of code.thanks

1
  • See also this answer. Commented Jul 9, 2012 at 15:53

3 Answers 3

3

An implementation of MVC explained along with how an observer pattern might work:

Up-to-date Swing MVC example + Question

Some guidelines to follow while using Swing:

GUI guidelines for swing

Sign up to request clarification or add additional context in comments.

Comments

1

MVC is a pattern to separate the Model, View, and the Controller. Swing is based on MVC, and is therefore called as PLAF (Pluggable look and feel)

In Swing its the Controller, that reacts when certain action is done, then the controller informs the Model to take actions according to the action done, and then its the controller that informs the View that there is some change in the model, then View changes itself to reflect the changes in the model.

How to Use MVC

1. Create SEPARATE Packages for the gui and business logic. eg:

com.demo.gui;

com.demo.logic;

2. Try to keep the Business logic away from GUI as far as possible, the code should be such that the same business logic can be applied with Swing for desktop apps and as well as with JSP for web development.

Comments

1

The Observer pattern is usually implemented with Listeners in Swing. This article explains how an MVC-like architecture is implemented for the Swing components themselves:

http://java.sun.com/products/jfc/tsc/articles/architecture/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.