my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enableEvent and Adapters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enableEvent and Adapters" Watch "enableEvent and Adapters" New topic

enableEvent and Adapters

Ranch Hand

Joined: Jul 20, 2000
Posts: 112
I am confused over this.
Can enableEvent and Adapters be used together ?
I think.... the answer is No.
Can anyone help ?

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The objective of enableEvent(...) is to make sure that the component gets the specifed event (ie. it's processEvent() method gets called) even if no listener is registered for that event.
Generally, a component does not do anything for a particular event if no listener is registered. So there is no point to pass the event to the component.
There may be needs where a component wants to do something even if no listener is registered.
For eg. You may want to create MyButton, which keeps count of how many times it was clicked. (Of course, this can be done by adding a listener) SO, it may enable action events and override it's processEvent method to keep the count. So even if no actionListener is added to it, it will still process the action event.
Now, Adapters are for a totally different reason. You can add a some subclass of say MouseAdapter and also explicitly call enableEvent() but calling enableEvent() would be redundant because adding a listener automatically enables the resp. event.
I don't know whether this is what you were looking for. Could you be more specific as to how you want to use them together?

Get Certified, Guaranteed!
I agree. Here's the link:
subject: enableEvent and Adapters
jQuery in Action, 3rd edition