每当用户关闭窗口时,我都想抛出异常,但我不确定这是否可能。这是我想做的一些代码:
import java.awt.event.*;
import javax.swing.*;
public class ExceptionTest extends JFrame{
public static void main(String[] args) {
try {
new ExceptionTest();
} catch (Exception e) {
e.printStackTrace();
}
}
public ExceptionTest() throws Exception{
super("Exception Test");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
//Throw Exception
}
});
pack();
setLocationRelativeTo(null);
setVisible(true);
}
}