Solved

Bi-Directional Events Handling in Swing Apps (best practices)

Posted on 2014-03-12
3
174 Views
Last Modified: 2014-06-18
Hi Experts,
I'm somewhat new to Java...
My current project is a controller app that connects to a piece of hardware via a socket connection.

I've made an an attempt to stick to the MVC model and added "Coms" (the socket connections etc) as a "subbranch" of "control".
The GUI is quite simple, a JFrame containing a JTabbedPane containing JPannels (and JTabbedPanes) and interactors (JButton, JTextFiled, JSlider).
The interactors on the GUI send out events to lookup some info in the "model" and then trigger messages sent to the hardware via the socket connection. To keep the connection between the UI and the Control classes soft, I've implemented a couple of interfaces to achieve above goal… So far so good.
The current issue is that the UI should also react to state changes on the hardware (a class that scan the status of the hardware once or twice a second).

Now to my question(s):

- Are there general rules how to structure (or where to put) the Listeners? (i.e. clump them all together in the JFrame - as one extreme or have one for each interactor (listening to "this").

- In my program the interfaces are implemented "unidirectional": the control classes are the "observer" the UI the "subject". How should I modify the program to make it bi-directional? The control classes are also subjects to be observed by the UI (since it has to update itself accordingly).

Many thanks for you input/suggestions/experience.

best,
K.
0
Comment
Question by:SonicMonk
  • 2
3 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 39924546
I'm not saying I can ultimately be of (much) help to you on this, but one thing that could be said is that a Java socket connection will only be able to send and receive data which can be passed over Input- and Output Streams. And that's quite a limitation seemingly in this case. But if the hardware is Java-enabled, then you could be ok.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 39925725
>> Are there general rules how to structure (or where to put) the Listeners?
As far as I know: no.
I would say the straight approach: each interactor should have its listener(s).
If you centralize all listening in the JFrame, then in addition, you need to make your interactors "listen/communicate" to the JFrame.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 40142067
Thanx 4 axxepting
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now