interface class ActionListener
The question is as follows: The following is a listing of the interface class actionListener from the Java API:
Code :
package java.awt.events;
import java.util.EventListener;
public interface ActionListener extends EventListener {
public void actionPerformed(ActionEvent e);
}
Explain the role of this interface in GUI programs written in Java.
I believe the action listener interface is there for receiving action events. The class that is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addActionListener method. When the action even occurs, that object actionPerformed method is invoked.
What more could be said about this?
Re: interface class ActionListener
What more needs to be said? You should probably provide more information about what type of information you are looking for.
If you are just looking to fill space for a homework assignment or something, you could probably mention that it is sometimes implemented as an anonymous inner class and explain situations where you might do this.
Re: interface class ActionListener
You could mention the theory of abstraction and polymorphism (this is the whole reason there are interfaces). If you want to get into more detail, you can even try to explain why Java chose to use single inheritance + interfaces instead of multiple inheritance (not really pertenant to ActionListener in particular, but rather towards all interfaces).