0
votes

I am writing a Java GUI application using the MVC design pattern. At first, I was putting the ActionListener classes for the JButtons as subclasses within the Controller. Then, I decided that I wanted the user to have the choice to be able to press a button OR the ENTER key to submit text in a text field. I read online that Action is better than ActionListener when you want more than one button click and key stroke to perform the same action.

I'm a little confused about where I should place the Action classes that extend AbstractAction when using the MVC pattern. Should they go in the in the Controller as subclasses the same way I was originally doing the ActionListener classes?

Also, If I place the Action classes as subclasses, my Controller will be pretty full of subclasses since I'll have a lot of buttons in the GUI. Is this the best practice?

1

1 Answers

0
votes

I ended up keeping the Action classes in the Controller and made the subclasses static like the answer to this question. I'm still not totally sure if this is the best practice, but everything works and I can reuse the classes for buttons and key strokes that perform the same action.