Two possible approaches are possible here: either you can simply call your myFunc method directly from the first example you give:
button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myFunc(e); } });
... Or you can define an inner class that implements the actionlistener, and then use it:
class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent e) {
On a futuristic note, when Java 8 hits the shelves (2013, so don't hold your breath), you can do it more briefly using closure.
source share