Take the 2-minute tour ×

I have a form that includes an area for putting in address information and a table that shows the addresses that have been added. I've separated out the ActionListener for the "add address" button on the form into it's own top level class and I'm finding it tricky and cumbersome to refer back to the form that has the text boxes and the table.

From a design perspective, is it a bad idea to put the class that implements the ActionListener for the add address button as an inner class in the form class? The ActionListener class will be specifically tied to the parent form alone, so I'm figuring that an inner class might be the better route to go. I'm going to perform any business logic outside of the form class, of course...

share|improve this question
why not just add a field in the listener, nothing cumbersome about that... –  ratchet freak Mar 7 '13 at 14:17
add comment

1 Answer

up vote 3 down vote accepted

Swing listeners are the typical example for inner classes, possibly even the reason that language feature was added. So go ahead and implement it like that. From the design perspective, the action listener behaviour is really part of the form.

share|improve this answer
Makes sense to me - just wanted to see if my reasoning is sound –  Zack Macomber Mar 7 '13 at 14:20
Anonymous inner classes usually. Lambdas in JDK8. –  Tom Hawtin - tackline Mar 12 '13 at 21:04
add comment

Your Answer


