1

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...

1
  • why not just add a field in the listener, nothing cumbersome about that... Mar 7, 2013 at 14:17

1 Answer 1

3

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.

2
  • Makes sense to me - just wanted to see if my reasoning is sound Mar 7, 2013 at 14:20
  • Anonymous inner classes usually. Lambdas in JDK8. Mar 12, 2013 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.