Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 54
couple of eclipse 5 35
use lov values 2 49
Adding multiple JVM environments to RedHat 6 7 17
This is an explanation of a simple data model to help parse a JSON feed
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

815 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

8 Experts available now in Live!

Get 1:1 Help Now