Reputation: 41
What is registration in Java? How do one registers a class to a method or another class?
Upvotes: 3
Views: 8804
Reputation: 63698
Registering is saving a object reference of one class to another.
For example,
JButton button = new JButton("Click Me");
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("YOU CLICKED ME");
}
};
button.addActionListener(listener); // register me
In the above code, Anonymous subclass of ActionListener
object is registered to button
object of class JButton
. The button
instance, in turn, will notify the click event by calling actionPerformed()
method of registered instance that it saved.
Upvotes: 2