• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on Card Layout usage in an MVC pattern.

 
sabin mash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have to create a GUI that has a frame with a card deck in the center and buttons at the bottom. The deck uses a card layout manager to display the data of 3 tab delimited files: 1) Customers.txt, 2) Projects.txt, and 3) Rates.txt. The program opens with the customer data showing. Pushing the buttons shows the corresponding data. Using an MVC design pattern for the program. Use the singleton design pattern for the frame and the deck classes.

I have done all of this for the most part. The buttons do indeed read the text from the files, utilizing the model to format the string that gets used in the display from the view. This MVC also uses a Mediator class that instantiates the view and controller, and facilitates the communication between them.

My questions is with the card layout manager. The program thus far places the text into the display straight as text. But i need that text to be in JPanels first, and those 3 JPanels will be the card deck that the buttons show, depending on which one you press (Customer button, Project button, Rates button). Where should this card layout be? Where should the text be placed into the JPanels, in the controller, or maybe the model? And where should these JPanels be added to the card layout?

I realize this is not an easy description to go off of, it may not be enough information for you. I can upload the entire thing if necessary. Thank you in advance!
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that many of your questions can be answered by going through the tutorial: How to Use CardLayout. So instead of asking somebody to write a tutorial for you, I suggest that you read the one which has already been written. (It's likely to be better than something which a Ranch member throws together just for one post.)

After you get through with that, let us know whether it helped. And if you have other questions which it didn't answer, go ahead and ask them here.
 
sabin mash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the swift response. I have read the Card Layout tutorial, but decided to read it again as you requested.

I think my question is not so much how to to use Card Layout, but rather where should each step of creating a functioning Card Layout be dispersed throughout an MVC pattern (if dispersed at all, maybe all of that code should be together).

For example, the demo in the tutorial you linked has the following method:


Should this code be in my Controller class? Or perhaps the Jpanel cards are created in my mediator class that I used to further decouple the View and Controller. This code likely would not go in my model classes, which is pure data housing. What is your best advice on where to create the card layout panels, add text to them, and add the panels to the layout?

Hope this makes sense. Thank you again.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should just go into the initialization code, shouldn't it? If you want to call that part of the Controller, that's fine with me.
 
sabin mash
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm embarrassed to ask this but, I'm still kind of new to all this, which initialization code do you mean?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, usually when you write a Swing program, there's a lot of code which starts by creating a JFrame and then continues by creating a lot of other Swing components, then it adds components to containers and listeners to components and so on until the complete GUI is all ready to go. Often that's all that you need to initialize things, unless there is the need to create and add new components later. But in your case it sounds like you have a predefined list of cards for your card layout, so you should be able to write one piece of code which sets up the whole GUI.

If you start at the beginning of the Swing tutorial, everything you see is going to be done that way for quite a while.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!