Twoja klasa powinna implementować ActionListener lub użyć obiektu anonimowej klasy ActionListener
Jaki jest najlepszy sposób implementacjijava.awt.event.ActionListener
berło?
Niech twoja klasa zaimplementuje ActionListener i doda to jako ActionListener:
class Foo implements ActionListener{
public Foo() {
JButton button = new JButton();
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
}
}
Lub dodaj obiekt anonimowej klasy ActionListener:
class Foo{
public Foo() {
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
}
}