简体   繁体   中英

JavaFX event handler vs change listener terminology

From my own research it appears that the terms 'event handler' and 'listener' are often used interchangeably and sometimes may mean the same thing. Some people (or frameworks) differentiate between them based on the listener being the object that is actually observing something and then may invoke the event handler procedure when an event occurs.

Anyway, I'm interested in JavaFX and I can firstly see how they have gone away from Swing where everything was generally a listener - in-fact I used to think of Swing having listeners that contained one or more event handlers, that would run depending on the event that occurred.

In JavaFX there are event handlers that are procedures that observe for events and run accordingly whenever a source they are attached to generates an event.

There are then ChangeListeners that 'listen' for change events on properties.

Even though I know the implementation of the two differ, would I be write in saying that generally speaking if we think of "event handling", is it correct to say that a ChangeListener is in essence an event handler that is specifically designed around listening for changes to properties. Whereas, more generally speaking the EventHandler interface allows a variety of other types of events to be handled, such as an ActionEvent, MouseEvent, etc?

I think that the ChangeListener can be considered a subset of EventHandler but it's not true because if you see the ChangeListener documentation you can notice that it doesn't implements the EventHandler interface (the ChangeListener implements the WeakChangeListener and the EventHandler implements the WeakEventHandler); however their use are similar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM