What is registration in Java? How do one registers a class to a method or another class?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With