PDA

View Full Version : [java] chiusura finestra


tsone1
08-06-2006, 14:16
1-Vorrei che al click sul tasto x della finestra la finestra venga chiusa con dispose();
2-al click sul tasto x della finestra la finestra , prima di chiudersi esegue una funzione

AbuJaffa
08-06-2006, 21:16
Doresti implementare WindowListener e controllare l'evento windowClosing:

esempio:

public class Test extends JFrame implements WindowListener{

public static void main(String args[]) {
Test frame = new Test();
frame.setVisible(true);
}

public Test() {
super("This is a test");
addWindowListener(this);
}

public void windowClosing(WindowEvent arg0) {
//esegui una funzione oppure dispose()
System.out.println("bye bye");

}
}

Ciao. ;)