Solved

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

Posted on 2014-03-12
3
177 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

914 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

19 Experts available now in Live!

Get 1:1 Help Now