Java窗体程序问题,关于父窗口与子窗口的关闭问题
两个窗口都是继承自JFrame,单击父窗口的按钮时弹出子窗口,但是关闭子窗口时父窗口也跟着关闭了,如何设置才能关闭子窗口时父窗口不关闭,而关闭父窗口时子窗口关闭。...
两个窗口都是继承自JFrame,单击父窗口的按钮时弹出子窗口,但是关闭子窗口时父窗口也跟着关闭了,如何设置才能关闭子窗口时父窗口不关闭,而关闭父窗口时子窗口关闭。
展开
1个回答
展开全部
jf.addWindowListener(new WindowListener(){
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
Window window =e.getWindow();
window.dispose();
}
@Override
public void windowDeactivated(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowOpened(WindowEvent e) {
}});
jf是子窗体。加上这句就行了。
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
Window window =e.getWindow();
window.dispose();
}
@Override
public void windowDeactivated(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowOpened(WindowEvent e) {
}});
jf是子窗体。加上这句就行了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询