相关疑难解决方法(0)

防止API中的System.exit()

System.exit()如果遇到异常,我正在使用第三方库.我正在使用jar中的API.无论如何,我可以阻止System.exit()调用,因为它导致我的应用程序关闭?System.exit()由于许多其他许可问题,我无法在删除之后反编译并重新编译jar .我曾经在stackoverflow中遇到过[我不记得的其他问题]的答案,我们可以使用SecurityManagerJava来做这样的事情.

java securitymanager

35
推荐指数
3
解决办法
1万
查看次数

基本Java Swing,如何退出和处理您的应用程序/ JFrame

使用这样的代码处理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)

java swing windowlistener

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×2

securitymanager ×1

swing ×1

windowlistener ×1