Results 1 to 4 of 4
  1. #1
    AWJustAGuy is offline Member
    Join Date
    Apr 2012
    Posts
    12
    Rep Power
    0

    Default How exactly does a view listen to the model in MVC?

    I understand the architecture. You have a model with data, a view that displays, and a controller that regulates between the two. What I don't understand is how you can update your view when the model changes (in push mvc format). Like if I have a textfield displaying an integer from my model, and my model changed, how would the textfield update?

    I'm told in my specifications to "The role of ModelChanged is to update the current view due to changes in the model. This class will have a handler/listener that implements the actionPerformed."

    Is there a specific type of action listener that knows when the model is changed?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: How exactly does a view listen to the model in MVC?


  3. #3
    AWJustAGuy is offline Member
    Join Date
    Apr 2012
    Posts
    12
    Rep Power
    0

    Default Re: How exactly does a view listen to the model in MVC?

    Thanks for the reply! I understand the link, but I was more wondering what specific listener code will query a model using actionPerformed? For instance, I could create a button that when pressed would access the controller who would then return the model's specific information to the view. But I have to click the button. How do I do this with something like a JTextField or a message or anything static, that doesn't require pressing?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: How exactly does a view listen to the model in MVC?

    Quote Originally Posted by AWJustAGuy View Post
    Is there a specific type of action listener that knows when the model is changed?
    You can see examples of these in the API: TableColumnModelListener, TableModelListener and TreeModelListener.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Model View Controller Help
    By gavo87 in forum Networking
    Replies: 0
    Last Post: 01-12-2011, 06:29 PM
  2. mvc-model view controller
    By hannes in forum AWT / Swing
    Replies: 5
    Last Post: 01-08-2010, 06:52 AM
  3. Model View Controller with Java
    By chopram in forum New To Java
    Replies: 8
    Last Post: 06-07-2008, 10:18 PM
  4. Model-View-Controller
    By Abnoba12 in forum Advanced Java
    Replies: 1
    Last Post: 05-15-2008, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •