Should your class implement ActionListener or use an object of an anonymous ActionListener class

前端 未结 3 2005
庸人自扰
庸人自扰 2020-12-05 06:03

What\'s the best way for implementing the java.awt.event.ActionListener interface?

Have your class implement ActionListener and add this as an ActionLis

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 06:29

    It depends. If you want to reuse the ActionListener across multiple components, option one is better. If the ActionListener will only ever be associated with the one button, option two is fine.

    Generally, you would create a separate class (or inner class), if you anticipate some growth in the project. There's no need for Foo to implement ActionListener.

提交回复
热议问题