Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
The gist. A custom component behaving like a button.
The main, parent class wants OwnComponent2Sw to call its actionPerformed method, when 'there's an Action event.
In its addActionListener method OwnComponent2Sw stores the reference to the main class's instance, lis, in an EventListenerList called ll.
In the list it can store all its listeners, so several other instances can have their actionPerformed called as well.
When OwnComponent2Sw is clicked, it retrieves its listeners one by one from the list.
Because the array's type is Object, we need a cast to ActionListener, ....
so we can call the listener's actionPerformed method.
To do this we need an ActionEvent.
Because EventListenerList is meant for all kinds of event listeners, not just ActionListeners, the listener type (ActionListener.class) along with the listener reference is stored in the list.
OwnComponent2Sw mimics a button, by drawing its text with or without an offset, determined in the mousePressed, mouseReleased methods.
EventListenerList can grow as needed.