相关疑难解决方法(0)

基本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 ×1

swing ×1

windowlistener ×1