?
Solved

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

Posted on 2014-03-12
3
Medium Priority
?
189 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 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 1500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Simple Linear Regression
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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