Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Eric Smith" Subject: MVC question regarding us Message-ID: X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 41 Date: Wed, 27 Apr 2011 15:30:22 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918222 96.60.20.240 (Wed, 27 Apr 2011 10:30:22 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:30:22 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:924 To: comp.lang.java.gui I'm writing a simulator for the trivial computer defined in Appendix C of _Computer Science: An Overview_ (9th Edition) by Brookshear. The computer has 256 bytes of memory. In my simulator, I have a Memory class that represents the main memory, and which supports a MemmoryEventListener interface for the GUI to track changes made by the simulation. I have a MemoryPanel class which extends JPanel and provides display and editing of the memory. It shows each memory location using a subclass of JFormattedTextField. If the user edits a location, a DocumentListener will be notified, and will call the Memory object to change the memory contents. The obvious problem is that without some care, a change to a memory location will trigger the MemoryEventListener, which will change the JFormattedTextField, which trigger the DocumentListener, which will change the memory location, which will trigger the MemoryEventListener, etc. I can easily imagine several solutions to this problem, none of which seem very elegant, and some of which wouldn't be thread safe. My question is whether there is any standard pattern used to solve this sort of problem. If not, I'll just roll my own ad hoc solution. I originally tried using a JTable for this, with my Memory class subclassing AbstractTableModel, but it was really obnoxious that JTable understands column headings and not row headings. I ended up having to put row headings in actual cells in my AbstractTableModel, and various ugly hacks like that, which seemed to defeat the purpose of separating the data model from the view and controller. I don't want my Memory class to have any idea how the GUI works. Thanks! Eric --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24