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 pattern for GUI 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 pattern for GUI" Watch "MVC pattern for GUI" New topic
Author

MVC pattern for GUI

Holmes Wong
Ranch Hand

Joined: Feb 18, 2002
Posts: 163
I am redoing my GUI design. In order to design MVC for GUI, I have to pass all graphic components in View through Controller to Model,
since Model need them to get user interactive data, for example: in order to get user selected
origin airport item, I have to pass originAirport
JComboBox reference to Model. This seems pressty messy. I am wondering if there is a way to get around it. Thanks.
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
The model shouldn't have to know anything about the view. When it's time to book a flight, the controller can ask the view which flight was selected, and then pass that info to the model.
In my particular implementation, the controller gets the selected row from the view, then gets the record number for that row from the table model, then passes the record number (and number of seats) to the model.
Holmes Wong
Ranch Hand

Joined: Feb 18, 2002
Posts: 163
Originally posted by Robin Underwood:
The model shouldn't have to know anything about the view. When it's time to book a flight, the controller can ask the view which flight was selected, and then pass that info to the model.
In my particular implementation, the controller gets the selected row from the view, then gets the record number for that row from the table model, then passes the record number (and number of seats) to the model.

Thanks, Robin for your reply.
TableModel is an exception here. I am talking about apply MVC to oher parts of GUI: view is the graphic presentation, controller handles events, model handles data.
For example, if we have a JComboBox component for origin airport, we show this box in view, assign listeners in controller, receive and handle data in model. But somehow, in order to get user choice from a list of origin airports, we have to pass the component to the model. This make implementation a bit messy. I am wondering if anyone who passed did the same.
By the way, I am using Mark's MVC scheme here.
Holmes Wong
Ranch Hand

Joined: Feb 18, 2002
Posts: 163
I am also wondering if anybody passed SCJD without using MVC in GUI except TableModel?
I believe its not good to pass references around,
or maybe I just cannot do this thing. Anyway,
I only want a passing score for this. Thanks.
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
I think of the model as including both the DataClient and the TableModel.
I don't think you need to implement the MVC pattern to pass.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Anyway,
I only want a passing score for this.

Holmes, if there is anything that we can teach to anyone taking this exam is to use it as a learning experience.
Just trying to pass this, is not the purpose of the certification. In order to make this Certifiaction really mean something, then you must try hard to learn from it in all ways. By working at doing your best, and more than just passing, I can guarantee you will be very thankful that you did, and you will be a much better developer for it.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Holmes Wong
Ranch Hand

Joined: Feb 18, 2002
Posts: 163
Thanks, guys. I aim at doing both. Just time is not on my side now.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Yeah I know time can be an issue. Good Luck and well be here to help.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC pattern for GUI