how to create an action listener in java

Java
button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) 
            {
              
            }
        });
Source

Also in Java: