thanks for any help / advice.
i was wondering on the best way to listen for custom events from components.
Say if i have a class (ClassA) that wraps (holds) a component (ClassB).... and i want that class (ClassA), to listen for custom events from the inner component class (ClassB).
For example, if i have a JTabbedPane, and it listens for when the tab is changed, i can pick that up from within this component, but what if i want this listened for in the outer class?
Whats the best way of doing this?
Those familiar with PureMVC (its a Mediator that is looking after a component).
Thanks for your reply.
I'm afraid dont really know how to rephrase it any clearer than:
i have a class (ClassA) that wraps (holds) a component (ClassB).... and i want that class (ClassA), to listen for custom events from the inner component class (ClassB).
Im not sure whats unclear about that sentence?
If class C must remain 'invisible' to class A, then you must involve class B. That is, Class B can refire the event, or class B can expose a get method letting class A see class C and thereby register and listen to it, etc.
If class C is visible to class A, then class A can simply register and listen to it.
wooooa - where did ClassC come from?
ClassA "has a" (contains) ClassB. Thats it.
ClassB could be e.g. a TabbedPane, and ClassA is just an ordinary class.
I don't want to pass any references in to any classes... i want to do it via the event listener model.
sam wootton wrote:I don't want to pass any references in to any classes...
Well, classB needs a reference to something to which it can send events. Doesn't have to be a reference of classA, though - it could be some event listening interface, like java.util.Observer. The drawback with that particular approach is that classB would have to extend java.util.Observable, which may or may not be feasible. But Observable doesn't do much, so you could implement something along these lines yourself with little effort.