java中如何设置Dialog关闭

lihongxu2010 lihongxu2010 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.awt.*;
import java.awt.event.*;
public class TestWindowClosing{
public static void main(String[] args) {
new FrameWindow("HELLO");
}
}
class FrameWindow extends Frame {
public static int i = 1; //设置计数器,计算窗口的数量,当界面没有显示窗口时退出系统
FrameWindow(String s) {
super(s);
setLayout(new FlowLayout());
setBackground(Color.yellow);
setBounds(300,300,400, 600);
setVisible(true);
Button bt = new Button("点击弹出窗口");
this.add(bt);
bt.addActionListener(new ButtonActionL());
this.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
i--;//每调用一次关闭事件,窗口数量减少1
setVisible(false);
if(i == 0) {
System.exit(0);
} else {
}
}
});
}
class ButtonActionL implements ActionListener {
public void actionPerformed(ActionEvent e) {
i++; //每调用一次,窗口数增1
FrameWindow c = new FrameWindow("子窗口");
c.setBounds(200,200,200,200);
c.setBackground(Color.blue);
c.setVisible(true);
Dialog a = new Dialog(c,true);
a.setVisible(true);
a.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
//System.exit(-1);
}
});
}
}
}
为什么无法关闭Dialog,请高手指点。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
lihongxu2010
Java SE 62,621 成员 307,251 内容