Pregunta

I've been trying to implement this action listener as stated above but keep receiving two errors:

-Cannot instantiate the type ActionListener
-void is an invalid type for the variable incrementAction

I've been looking up similar examples but they all seem to point to the same method of implementing it. This is where I've got to.

        increment.addActionListener(new ActionListener());{
        public void incrementAction(ActionEvent e){
            this.incrementCount();
            this.setTextField();
        }
    }
¿Fue útil?

Solución

The signature of the ActionListener method is:

public void actionPerformed(ActionEvent e)

JButton increment  = new JButton();
increment.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("ActionEvent received! ");
    }
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top