System.exit()如果遇到异常,我正在使用第三方库.我正在使用jar中的API.无论如何,我可以阻止System.exit()调用,因为它导致我的应用程序关闭?System.exit()由于许多其他许可问题,我无法在删除之后反编译并重新编译jar .我曾经在stackoverflow中遇到过[我不记得的其他问题]的答案,我们可以使用SecurityManagerJava来做这样的事情.
使用这样的代码处理JFrame的好方法是什么?我想处理Window出口和窗口关闭.
我知道我们不应该使用System.exit();
public class JavaCellularAutomataSquare {
public static final String TITLE = "Cellular Automata - Squaring Example";
private int maxWidth = 600;
private int maxHeight = 600;
public void launch() {
final JFrame frame = new JFrame(TITLE);
frame.setLocation(20, 20);
frame.setPreferredSize(new Dimension(maxWidth, maxHeight));
frame.setResizable(false);
frame.setFocusable(true);
final JPanel panel = new JPanel();
panel.setLocation(20, 20);
panel.setVisible(true);
panel.setPreferredSize(new Dimension(maxWidth, maxHeight));
panel.setFocusable(true);
panel.setBackground(Color.white);
// Panel setup, toggle visibility on frame
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)