gpt4 book ai didi

java - 使用 2 个 jframe 的 Swing Jframe

转载 作者:行者123 更新时间:2023-12-01 06:11:45 26 4
gpt4 key购买 nike

我有 2 个扩展 Jframe 的类。我想在单击按钮时调用第二个 Jframe,并在单击关闭时返回。所以在第一个 JFrame 上我写了这段代码

public void actionPerformed(ActionEvent e) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Lessons frameLessons = new Lessons();
frameLessons.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

但是当我尝试关闭第二个 Jframe 时,第一个 Jframe 也会关闭

最佳答案

试试这个:

Lessons frameLessons = new Lessons();
frameLessons.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frameLessons.setVisible(true);

关于java - 使用 2 个 jframe 的 Swing Jframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194929/

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