Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #924

MVC question regarding us

From "Eric Smith" <eric.smith@THRWHITE.remove-dii-this>
Subject MVC question regarding us
Message-ID <qhd54dt79c.fsf@ruckus.brouhaha.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:30 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

MVC question regarding us "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
  Re: MVC question regardin "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000
    Re: MVC question regardin "Eric Smith" <eric.smith@THRWHITE.remove-dii-this> - 2011-04-27 15:30 +0000

csiph-web