The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
A bean class can fire off any type of event, including custom events. As with properties, events are identified by a specific pattern of method names.
public void add<Event>Listener(<Event>Listener a) public void remove<Event>Listener(<Event>Listener a)
The listener type must be a descendant of java.util.EventListener
.
For example, a Swing JButton
is a bean that fires action
events when the user clicks on it. JButton
includes the following methods (actually inherited from AbstractButton
), which are the bean pattern for an event:
public void addActionListener(ActionListener l); public void removeActionListener(ActionListener l);
Bean events are recognized by builder tools and can be used in wiring components together. For example, you can wire a button's action
event to make something happen, like invoking another bean's method.