File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "MVC" Watch "MVC" New topic
Author

MVC

Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Hi everybody!

I like to get one or more opinion about my MVC [VC] to be exact! When i read and learn some thing about MVC i have a lot of theoretical examples, but no much practical examples... My doubt is simple: is this correct? (see pseudo-code)

MyController c = new MyController();

MyView v = new MyView(c);

//Inner MyView class exists a constructor:

MyView(MyController c){
c.setScreenToControl(this);
}

Is this Correct? Or there is a best way to associate controller/controlled classes?

Thanks!


Julio Cesar Lopes Marques
Sun Certified Java Developer 5, Sun Certified Java Programmer 5
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Fala Julio!

Since we are talking about Swing, you can face ActionListeners as controllers, and JFrames as views. This is how I did the main window of my project:



So you can have an instance of the view in the controller.

Here is a very interesting article about GUI architectures, which also talks about the MVP pattern (a kind of MVC). I think it might be helpful!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Julio Cesar Marques
Ranch Hand

Joined: Mar 21, 2009
Posts: 66
Thanks again Bob!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

Is there any difference between doing it like Roberto showed and using a seperate (anonymous) (inner-)class? And i mean difference in good or bad, from a design perspective ? I know there is a difference in code


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC