define events for self-made component

Hi,

I created a component which formed by a panel and some basic components. Now I would like to make this component to have its self event handler, so that outside dialog can add/delegate this event.

what I want to do is to pass a structure from the self-made component to dialog on every changes of the value.

Could some of you give me some hints on How to define this event?

Thanks a lot !

[424 byte] By [mcstevenjpa] at [2007-11-27 4:37:31]
# 1

Check out the "observer" pattern and model your code after that. You can find a brief synopsis of it in wikipedia [url=http://en.wikipedia.org/wiki/Observer_pattern]here[/url], or even better, get the "Head First Design Patterns" book, or better still, the GOF book.

Also, emulate what Swing does w/ its events. It is essentially using the observer pattern.

petes1234a at 2007-7-12 9:47:47 > top of Java-index,Desktop,Core GUI APIs...
# 2

Have you considered using a [url=http://java.sun.com/javase/6/docs/api/java/beans/PropertyChangeListener.html]PropertyChangeListener[/url]? Swing components already contain the wiring necessary to emit PropertyChangeEvents, which makes it much more attractive than defining your own event types.

uncle_alicea at 2007-7-12 9:47:47 > top of Java-index,Desktop,Core GUI APIs...
# 3

Here's an excellent article for you I found at Java world that describes java.util's construct of the Observer Pattern. Click on this: [url=http://www.javaworld.com/javaworld/jw-10-1996/jw-10-howto_p.html]Observer and Observable: An introduction to the Observer interface and Observable class using the Model/View/Controller architecture as a guide[/url]

Hope it helps!

petes1234a at 2007-7-12 9:47:47 > top of Java-index,Desktop,Core GUI APIs...
# 4
After reading uncle alice's post, I think that you are probably better off using his (her?) recommendation, but still, read my articles, cuz knowledge of design patterns will help you immensely in the long run./Pete
petes1234a at 2007-7-12 9:47:47 > top of Java-index,Desktop,Core GUI APIs...