<< Back to Part 2 of our Java MVC Example
Whenever the user adds, edits, or deletes data, such as our Process data, all the proper GUI components need to be notified of this event so they can properly update their displays. In this application, when a user adds a new Process, this means that we need to update our MainProcessTable. We implement this as follows:
processDao.insert(process);processes.add(process);processes object, it already has the new data, and the last thing I need to do is to tell the TableModel to fire its fireTableDataChanged event. Firing this event tells the listeners of this event that the TableModel data has changed, and you're going to want to repaint yourself. In this example, this specifically means that the MainProcessTable will repaint itself, correctly showing the new data. If other GUI components have registered themselves as listeners of the MainProcessTableModel, they will also be updated.I hope this has served as a good example of how to use the Model View Controller (MVC) pattern in a real-world software application. If you'd like me to add any more detail to this article, or you have any other questions or comments, just use the comment form below.
<< Back to Part 2 of our Java MVC Example
Before I leave, here are links to some of our other Model View Controller (MVC) content:
Post new comment