The fact is that when you declare your class myButton
to implement ActionListener
, you increase its visible API (i.e., add a new public method actionPerformed()
, freely called by any code that contains a link to myButton
).
Since you probably don't want the " actionPerformed
" to be part of the myButton
API, you should use an inner class that will keep the open myButton
API.
Note that Swing classes are full of bad examples, such as those where public methods are explicitly commented as โimplementation details, do not call directly,โ is actually a very poor design decision.
source share