Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
Two different components,...
but both contain an actionPerformed method.
They have the PRESENCE OF THIS METHOD IN COMMON ,....
but the implementations DIFFER .
They both implement ActionListener.
ActionListener is an interface . Its full name is java.awt.event.ActionListener .
It contains only the description of the actionPerformed method,....
NO IMPLEMENTATION ! An interface can not contain instructions.
Because both components implement the interface, ....
they can be registered with the Button as ActionListeners.
So they're not only Panels,....
but ActionListeners, as well .
A component that is NOT an ActionListener, can NOT be added as an ActionListener, because the compiler accepts only ActionListener as the parameter's data type.
As coded in the Button class source code.
This shows that an interface can be USED AS DATA TYPE .
A class that implements an interface MUST CONTAIN ALL METHODS SPECIFIED in that interface for it to be instantiated.
An interface results in a binary .class file after compilation.
An interface can extend another one.