gpt4 book ai didi

java - 在关闭 JFrame 之前我将如何执行函数

转载 作者:行者123 更新时间:2023-11-29 09:30:45 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Call a method when application closes

我想在使用 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 关闭我的 java 应用程序之前调用一个方法;我已经尝试使用 windowClosed/windowsClosing 的 WindowListener,但它不起作用。 看起来像这样

public class exampleFrame JFrame implements{

public exampleFrame (){
this.addWindowListener(new windowAction());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

class windowAction implements WindowListener{

@Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowClosed(WindowEvent e) {
System.out.prinln("window closed")

}

@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.out.prinln("window closing")
}

@Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub

}

@Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub

}

}

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com