What is the best way to implement the java.awt.event.ActionListener interface?
Ask your class to implement an ActionListener and add it as an ActionListener:
class Foo implements ActionListener{ public Foo() { JButton button = new JButton(); button.addActionListener(this); } public void actionPerformed(ActionEvent e) { } }
Or add an object of the anonymous ActionListener class:
class Foo{ public Foo() { JButton button = new JButton(); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); } }
java swing actionlistener
elias Jul 11 2018-12-12T00: 00Z
source share