我有2 jframes(假设A和B),当我关闭一个jframe(A)我需要显示其他jframe(B)我有一个线索,我需要覆盖defaultClosingOperation,但我不知道如何做到这一点。任何帮助都将不胜感激。谢谢大家。
你可以添加一个Windows监听器到你的框架。
WindowListener myExitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirmation = JOptionPane.showOptionDialog(jframe1, "Open frame2", "Open frame2", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirmation == 0) {
//open jframe2 here
}
}
};
jframe1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
jframe1.addWindowListener(myExitListener);