Java Reference
In-Depth Information
package java.awt.event;
public interface ActionListener extends java.util.EventListener
{
public void actionPerformed(ActionEvent e);
}
Notice that ActionListener extends EventListener and is in the java.awt.event
package, which is where all the AWT event classes and listener interfaces are
defined. The javax.swing.event package contains the event classes and listener
interfaces unique to Swing. The AWT components only generate AWT events,
while Swing components generate both AWT and Swing events. For example,
a Swing JButton is the source of java.awt.event.ActionEvent (an AWT event
class) and a javax.swing.event.ChangeEvent (a Swing event class).
Notice also that the ActionListener interface contains one method, and the
parameter is an ActionEvent. When an action event occurs, the source of the
event instantiates an ActionEvent object and invokes actionPerformed() on all
listeners, passing in the ActionEvent object.
An event listener interface can contain any number of methods. The meth-
ods are used to determine what caused the event. With ActionEvent, there is
only one method, actionPerformed(), which simply means that the action has
occurred. For example, with buttons it means the button was clicked.
The WindowListener interface has seven methods, and the method that the
event source invokes depends on what caused the WindowEvent. Win-
dowListener is defined as:
package java.awt.event;
public interface WindowListener extends java.util.EventListener
{
public void windowOpened(WindowEvent e);
public void windowClosing(WindowEvent e);
public void windowClosed(WindowEvent e);
public void windowIconified(WindowEvent e);
public void windowDeiconified(WindowEvent e);
public void windowActivated(WindowEvent e);
public void windowDeactivated(WindowEvent e);
}
For example, when a user clicks the X to close a window, the window instan-
tiates a new WindowEvent and invokes the windowClosing() method on
all registered listeners. Similarly, minimizing a window causes window
Iconified() to be invoked, restoring a window causes windowDeiconified() to
be invoked, and so on. The window invokes the appropriate method on the lis-
tener, depending on what caused the WindowEvent.
Search WWH ::




Custom Search