如何检查 JFrame 何时关闭?

2022-01-24 00:00:00 java swing jframe

如何检查JFrame 窗口何时关闭?

How do I check when JFrame window is closed?

MediaPanel mediaPanel=new MediaPanel();
JFrame_of_subtitle frame=new JFrame_of_subtitle(mediaPanel);
JPanel panel=new JPanel();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

推荐答案

您将添加 WindowListener 到你的框架.

You will add WindowListener to your frame.

WindowListener 有一个 windowClosing 回调函数,将在您的框架关闭时调用.

WindowListener has a windowClosing callback function which will be invoked when your frame is being closed.

您可以查看此教程以获取示例代码.

You can see this tutorial for sample code.

相关文章