This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have see two implementations of a MouseListener interface and I am a little confused. In the first one I add "implements" to the class and implement the methods.
In the second example (shown below) uses an inner class to implement the MouseListener. Both examples seem to work fine, but I am confused by the use of "new MouseListener()", since it is an interface, not a class.
I much prefer the second solution, which Rob has told you is called an anonymous class. You can see all sorts of examples where the parent Component implements an interface and the fooPerformed(FooListener f) method is full ofIf you add Listener objects to the individual Components, you can get direct communication between related objects.
Joined: May 16, 2008
Thank you Rob and Campbell, the clues help me find this article on using the anonymous classes to implement interfaces.