Please help me understand the difference between adding an action listener to the JComponent in the following two approaches.
First method: implementing an actionListener for my class and adding a generic actionPerformed method that selects an event-based selection
class Test implements ActionListener { JButton jbutton = null; public Test(){ jbutton = new JButton(); jbutton.addActionListener(this); } public void actionPerformed(ActionEvent e){
The second method: defining an action listener for an individual JComponent.
JButton jbutton = new JButton(); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {
What is the difference between the two approaches and which one is cleaner and easier to maintain, and if there are any performance benefits?
source share