• Post Reply Bookmark Topic Watch Topic
  • New Topic

MVC : How to pass object from model back to View

 
Moniphal Say
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm new to Swing, now i work on the project that use MVC pattern. I try to seperate my application into 3 packet, model view controleur (ActionListener). I write one small application, in view, i create texte field and one button. When user click on button the controleur pass the texte to the model. I just try to change some content of the texte and I want to write that texte on the view, but i dont know how to pass that text to view. Any idear on this, i really appriciate your help.

Moniphal
[ January 25, 2005: Message edited by: Moniphal SAY ]
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField.setText("update string");
 
Moniphal Say
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
Mike, thanks for your reply. My problem is that in my class View, I cant not get the texte from class Model. I dont know how to pass the texte to the view.

I have classe View.java, in that I add JTextField and JButton which I set the actionCommand and addActionLister to the button.
I have classe MyActionListener.java extends ActionListener, in which I can get the texte from the JTextField in View.java and store in variable "texte". And I call one method of class Model.java that I passed variable "texte" as argument.
In the method of class Model, I change the contente of the variable texte and I want to write that texte in View or call the method repaint() of View or make the view call repaint() automatically. Is there any way to do that or it cant be do that?

Regards,
Moniphal
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the best of my knowledge in an MVC pattern the View and the Model have a reference to each other. The View would implement some listener interface of the Model, and the View would hold onto a reference of the Model, usually an Interface type.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!