Reputation:
What is the difference between an ActionListener and an EventListener, especially in the context of Java GUI development?
Upvotes: 9
Views: 11342
Reputation: 2136
Although the meaning can differ by platform, in the context of Java Swing an ActionListener
implements a function actionPerformed(ActionEvent)
that will do something when a user does some action, according to this Oracle tutorial. An ActionListener
is a subinterface of EventListener
. EventListener
contains several subinterfaces, for example MouseWheelListener
, which does something when the user moves the mouse wheel.
Upvotes: 1
Reputation: 1180
The ActionListener interface is utilized for treating action events. For illustration, it's used for button clicks by a JButton, for checking by JCheckbox and unchecking, by a JMenuItem when an option is picked and a lot of other graphical components.
It's a uncomplicated interface with only one technique:
public interface ActionListener extends EventListener
{
public void actionPerformed(ActionEvent e);
}
An event listener is used to practice events. For instance, a graphical component similar to a JButton or JTextField is acknowledged as event sources.
This indicates they can generate events - when a user relates to on the JButton or types text into the JTextField. The event listener’s job is to catch those events and do incredible with them.
Upvotes: 1
Reputation: 46193
The interface ActionListener
is a subinterface of EventListener
. In practice, it is probably better to implement the most specific interface you can, such as ActionListener
or WindowListener
.
Upvotes: 7