This is a really good question, IMHO ... the one I asked a couple of years ago on the Sun Java forums (now basically non-existent, thanx for Oracle, a half-bloated package of febrile fiscal fascists).
At the beginning of putting order in kaos, which is your typical “first cut” GUI, Google for Swing MVC. The first article I read on this topic was the JavaWorld "MVC Meets Swing . " I was lucky because it explains the PROBLEMS and also offers reasonable solutions (with examples). Read this and go to Google for an “advanced reading” and hit us with any specific questions coming from this.
At the front of “simulated user activity” you have nothing to worry about ... you only need to observe the external conditions, say, you find that the local file has been updated (for example) and, in turn, raise a “notification to registered listeners (listeners) ... with the only difference being that you are implementing a “speaker” and “listener.” The Swings Listener interface can be reused for messaging (or not, at your discretion). Nothing complicated here.
The "uplift" of the "event" is absolutely straightforward. Basically, you just call the "EventHappened" method for each of the registered listeners. The only difficult bit concerns the “multithreading” that is inherent in all non-trivial Swing applications ... otherwise they will work like three-legged dogs, because EDT (google it) constantly does everything, and not just drawing and message broking (that is, for what it intended). (As Ignis said earlier) The SwingUtilies class provides several convenient invoke methods for "raising events" on EDT.
There is nothing special about Swing applications ... Swing has a pretty steep learning curve that everything, especially multithreading ... a topic that I had previously avoided, like a plague, like "too complicated for a modest brain like mine." Needless to say, it was an unreasonable fear. Even an old idiot like me can figure it out ... it will take more time, and all that.
Greetings. Whale.
source share