Mazzy
Mazzy

Reputation: 14227

building swing gui using mvc pattern with observer pattern

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

Upvotes: 2

Views: 4233

Answers (3)

chubbsondubs
chubbsondubs

Reputation: 38895

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

Upvotes: 3

lbalazscs
lbalazscs

Reputation: 17809

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/

Upvotes: 1

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33544

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.

Upvotes: 1

Related Questions