Just "discovered" the newly (in JDK 1.4) added java.beans.EventHandler which allows you to do stuff like:
but.addActionListener(
(ActionListener)EventHandler.create(ActionListener.class, target, "myButtPressed", ""))
which when but
is pressed the method called setMyButtPressed(ActionPerformed event)
will be called.
This stuff actually safes alot of typing AND memory usage + even gain some performance if the HotSpot is nice to you ;)
That was the good thing - the BAD thing is that EventHandler.java only works for public properties! And that is bad since it would break good old encapsulation....
So, does anyone have a EventHandler replacement class somewhere ? One that allows any method to be called when a certain event occur (no matter it's private, protected, default or public) ?