ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### JFrame不具备模态窗口的条件 ``` Window类的构造: Window(GraphicsConfiguration gc){} //Frame和JFrame采用了这个构造方法 //下面这三个构造方法才能拓展出模态窗口,因为它们指定了一个Frame或Window作为其所有者 Window(Frame owner){} Window(Window owner){} Window(Window owner, GraphicsConfiguration gc){} Dialog继承的是Window类,它的构造如下: public Dialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc) { super(owner, gc); //重点在这里,所以它可以设置模态 this.title = title; this.modal = modal; setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy()); } JFrame和它的父类Frame的构造: public Frame(String title, GraphicsConfiguration gc) { super(gc); //采用了Window的第一种构造 init(title, gc); } ```