Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

Event passing in (Swing) GUI Application

Thread view: 
Wardie - 31 Jan 2006 14:51 GMT
Hi,

I'm build a GUI app using Swing.  I want to have it be as modular as
possible for all the usual reasons including reuse of common
components.

Some of my componets are GUI panels, some are non-GUI classes.

I'm a little confused as to the best way to communicate between
components though.  When I use a Swing Jxxx widget I can register
EventListeners and FocusListeners etc.  What sort of event mechanism
should I be using to talk between my higher level application
components?

I've gone with use PropertyChangeEvents for now should I be used custom
events though?

Or is this all down to my own design.  I guess I'm asking for "What, if
any, is the usual event mechanism between GUI/non-GUI objects?"

Anyone got any good resources online?
Monique Y. Mudama - 31 Jan 2006 16:49 GMT
> Hi,
>
[quoted text clipped - 15 lines]
> Or is this all down to my own design.  I guess I'm asking for "What,
> if any, is the usual event mechanism between GUI/non-GUI objects?"

I think that yes, this comes down to your own design.

You can even create your own Event/Listener scheme, with or without
inheriting from any particular API Event.

> Anyone got any good resources online?

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

JFalt - 01 Feb 2006 14:20 GMT
I find that using custom events leads to much cleaner code that is much
more easily expandable.  In cases where you have a particularly complex
GUI with many components within components, custom events are a simple
way to adhere to encapsulation and avoid  repeating functionality in
various classes.  By using custom events, new modules can be plugged in
and operate autonomously, and yet still have the ability to interact
with the other classes where necessary in a standard way, meaning you
won't have to hack up your code everytime you want to expand the
functionality.
Ian Mills - 04 Feb 2006 10:37 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>
> Anyone got any good resources online?

It really comes down to what information you are trying to communicate
between the classes. For instance if you have a button on your GUI and
you want to tell your non-GUI class that it has been pressed the
standard ActionListener is the way I would go. When I am writing code I
tend to take the view "why re-invent the wheel" - or in other words if
there is already a standard listener that does what you want then use it
and if there isn't then you will have to write your own. You can of
course also adapt existing listeners to do what you want - e.g.
PropertyChangeListeners normally get fired when the bounds of a
component have changed but there is nothing to stop you firing your own
PropertyChangeEvent when the contents of a text field has changed.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.