Totéž bez anonymity...

class MyWindowListener implements WindowListener {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}
    ...
okno.addWindowListener(new MyWindowListener());