Solved

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

Posted on 2014-03-12
3
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

696 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