aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Customized Data model help needed 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 » Java » Swing / AWT / SWT
Bookmark "Customized Data model help needed" Watch "Customized Data model help needed" New topic
Author

Customized Data model help needed

Ajit Malleri
Greenhorn

Joined: Feb 10, 2002
Posts: 27
The scenario is that I have a swing frontend which listens to messages from the servlet. What I need to do is to display the data in the swing frontend as and when the data changes. I had seen a posting in some site suggesting setting up a data model which will hold the data. This model could fire events to indicate the changes occuring. All the gui screens would register as listeners to this data model and update themselves as and when the changes take place.
In my swing frontend, I have 3 JTable and one JTree. I want all the data to be updated.
Can someone throw some light on this issue and show examples on how to:
(1) create a data model
(2) fire events to indicate changes
(3) register the screens to the data model
Any help would be highly appreciable.
Thanks,
Ajit
[ December 08, 2002: Message edited by: Ajit Malleri ]
[ December 08, 2002: Message edited by: Ajit Malleri ]

SCJP, SCWCD
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
hi,
(1) and (2) The data model should have get and set methods to change the data, and methods (protected) to fire events.
Example:

for more information on the event pattern, see:
http://www.artima.com/designtechniques/eventgen.html
If you have several tables and a tree, I'd suggest you create one "main" data model that holds your data and that you give as argument to the TableModel and TreeModel implementations (inherit at least from AbstractTableModel and AbstractTreeModel, they implement the event generating methods). These will delegate data requests to the main model and provide view specific implementations such as getColumnName(int col) etc. See the swing tutorial on table and tree models.
(3) These tree and table models should be handled to the view classes that can register listeners on them. JTable and JTree do that automatically, anyway. If you implemented all the methods in the table and tree models well, you shouldn't need to change the JTable and JTree implementations. They will reflect all changes in the data models by themselves. Of course, you can register listeners to make other changes to your interface (change frame titles, menu bars, button states etc.).
Chantal
[ December 10, 2002: Message edited by: Chantal Ackermann ]
[ December 10, 2002: Message edited by: Chantal Ackermann ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Customized Data model help needed
 
Similar Threads
JLists dont refresh
MVC with two Model interfaces
need help regarding applet-servlet communication scenario
How do I apply Model-View-Controller in Java Swing?
Applying pure MVC to Swing/JFC