How does Jbutton addActionListener method takes object of any type?

No. It has a parameter of ActionListener type. You cannot invoke .addActionListener(new Object());. You can invoke:

button.addActionListener(new ActionListener() {
    @Override public void actionPerformed(ActionEvent e) {
        // Stuff to do.
    }
});

You should also really read the documentation for this.

Leave a Comment