What is the difference between implementing the event handler using a \"Listener
ID: 3561915 • Letter: W
Question
What is the difference between implementing the event handler using a "Listener" vs. an "Adaptor"? Choose a unique(i.e., different from classmate's entries) listener type and describe the event that causes the methods of the listener to be invoked. In addition, describe a scenario where that listener type will be used in an application.
The following Java Tutorial link provides information related to listener.
http://java.sun.com/docs/books/tutorial/uiswing/events/eventsandcomponents.html
Note: No Plagiarism
Explanation / Answer
a)
Listener
Adapter
A Listener is an Interface.
An Adapter is a class.
When a Listener is used in a program, all the methods in the Listener interface should be overridden.
By using the Adapter class, there will be no need to implement all the methods unnecessarily.
A class has to implement the Listener.
A class has to extends the Adapter
Listener interface increases the content of the program.
Adapter class reduces the clutter of the code.
---------------------------------------------------------------------------------------------------------------------------------------
b)
MouseListener:
Mouse is one of the input devices of the computer. Basing on the user
Listener
Adapter
A Listener is an Interface.
An Adapter is a class.
When a Listener is used in a program, all the methods in the Listener interface should be overridden.
By using the Adapter class, there will be no need to implement all the methods unnecessarily.
A class has to implement the Listener.
A class has to extends the Adapter
Listener interface increases the content of the program.
Adapter class reduces the clutter of the code.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.