aspose 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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

Rachna Chaturvedi
Greenhorn

Joined: May 02, 2002
Posts: 21
hello all,
I am trying to design the client for the FBN system using MVC, but i am lost and need some help.
Can someone help me define the responsibilities of classes in this pattern and the events that need to be generated to communicate . Also do we need to generate special events to handle search and book request for the client .
Please explain giving names to classes eg the following, as it will help me proceed
(1) FBNClient
(2) FBNController
(3) FBNModel
(4) FBNSearchEvent
(5) FBNSearchListener, etc etc
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Regarding the use of MVC in GUI, here is a thread where Mark and others offer good advice.
Eugene.
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
You need a
1) class to extend JFrame
1) TableModel class to store flight search results
2) controller to handle events generated by all the gui components
3) Facade to iteract with the controller and the Data instance or you communicate directly from the controller to Data instance.
Controller can have listeners as inner classes to handle gui events.
Rachna Chaturvedi
Greenhorn

Joined: May 02, 2002
Posts: 21
Hi sai
what kind of events should the gui generate, i mean is it just the events or the higher level events like SearchFlight etc, and if it is the awt event , how is the search or booking actually done,
I understannd from your mail that the listeners (as inner classes) are the actionListener etc . please advice
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
In the controller you will have listeners to handle,
1) search flight ActionEvent
2) book flight ActionEvent
3) Any ActionEvent generated by JMenuItem(s)
4) Any WindowEvent generated by the JFrame
Rachna Chaturvedi
Greenhorn

Joined: May 02, 2002
Posts: 21
Thankyou sai, this clears my controller repsonsilibilties, i understand that the searchflight, bookFlight action event in the controller talks to the Model., that queries the database ( is that right??) .
So what should the model class do, does it store data , in terms of attributes like Origin, destination etc of each flight ??? i always get lost at this point in my design ???
Thanks in advance
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Rachna,
There are so many ways to do it. There is no correct way to implement MVC. In any case, you have to think the view as GUI components, model as data and controller as the listener for all the gui actions. In this assignment, table model is the only seperate class as far as the model is concerned. Rest of the data is handled directly by the controller. You can also develop the table model as a reusable class for future requirements. The table model can function based on only Object instances instead of DataInfo or FieldInfo. If you are using Facade, controller can communicate with the Facade using String objects only. Facade can translate the DataInfo or FieldInfo to String objects. Facade will have the bookFlight() and searchFlight() methods.
In my submission, I regret to tell you that I didn't have Facade. I handled the translation in the Controller.
[ June 20, 2002: Message edited by: Sai Prasad ]
Rachna Chaturvedi
Greenhorn

Joined: May 02, 2002
Posts: 21
ThankYou sai, i am now clear., Thanks again
Rachna
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
Sai,
I like your suggestion. I think I will add a facade so my controller does not need to know about DataInfo or FieldInfo.
I've been almost done with this assignment for about a month, but I keep redesigning for improvements. Some day I'll finish!
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
In addition to Controller and Facade, I also have a Mediator to hold the values from the GUI.
So,
-- GUI just displays the cntrols and knows nothing about any other class
-- Mediator holds the critical values from the GUI, such as selected flight number, number of seats to book, origin airport, destination airport.
-- Controller uses mediator to get the necessary fields entered in GUI and calls methods such as searchFlights(), bookFlight() which are implemented in Facade (I call this class DataServices).
Eugene Kononov.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC pattern for GUI
 
Similar Threads
client design
How to Integrate ActiveMa
Swing GUI Method Access Question
GUI Frustration - help NEEDED!
MVC