button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("hello world!");
}
});
import java.awt.event.ActionListener; //For action listener
import javax.swing.*; //For JButton
// Inside of function or method
JButton button = new JButton();
button.addActionListener(e -> {
System.out.println("Another way of writing an action listener.");
})