急急急!!!如何关闭当前JFrame窗口? 在网上搜了一下都说dispose()可以关闭窗口,可是发现dispose()只能把窗口隐藏掉,我后面的程序照样还在运行中。请问什么方法可以关闭当前的JFrame窗口并停止运行程序?(不能使用System.exit())。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);??? 对Jframe了解的很少,不知道用setVisiable是不是可以阿?帮你顶一下!! setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) dispose()方法释放由此 Window、其子组件及其拥有的所有子组件所使用的所有本机屏幕资源。即这些 Component 的资源将被破坏,它们使用的所有内存都将返回到操作系统,并将它们标记为不可显示。这个不光是不显示。也会释放资源啊。。怎么会不管用呢,我们一直都这么用啊 说明下:setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)是手动关闭框架时的响应动作,用于包含多哥框架集中,关了其中一个框架程序不会退出! 其实,这个方法也是隐藏框架.隐藏框架就可以了,你非要关做什么?退一步dispose()方法够用了. public void setDefaultCloseOperation(int operation) { if (operation != DO_NOTHING_ON_CLOSE && operation != HIDE_ON_CLOSE && operation != DISPOSE_ON_CLOSE && operation != EXIT_ON_CLOSE) { throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE"); } if (this.defaultCloseOperation != operation) { if (operation == EXIT_ON_CLOSE) { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkExit(0); } } int oldValue = this.defaultCloseOperation; this.defaultCloseOperation = operation; firePropertyChange("defaultCloseOperation", oldValue, operation); } }/////////////////////////////////////////////////////////public void checkExit(int status) { checkPermission(new RuntimePermission("exitVM")); }/////////////////////////////////////////////////////////operation == EXIT_ON_CLOSE 时,直接都退出 虚拟机了 难道还只是隐藏? 设置JFrame.EXIT_ON_CLOSE只会在点窗口右上角的“X”时会有System.exit()的效果,对于在窗口中的按钮没有任何作用啊!而且即使是那个“X”也不是我想要的效果~~~~~~~~~~~~~~~ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);就这样 f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });加这监听,当点激"X"时就会关闭窗口也可以用new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }另写一个事件触发关闭窗口 button.addActionListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });点激button关闭窗口 jframe.dispose() 方法,会关闭该窗口,与点击右上角的X的功能一样。如果之前对jframe注册过窗口事件,那么也会触发其监听器。 关于线性表中出入的问题 强大的ByteArrayOutputStream难道可以获得缓存区的数据并且转换为数组? 求javax.media包 Java中的那些控件如何才能更好的控制啊?(比如说,JLabel,JButton, 文体框等啊)急啊! notify和notifyAll为什么在sychronized(this)时,效果一样??? GUI桌面应用程序 JarInputStream复制jar,输出的jar比原来的大 新手--学习Java应注意什么 有问题请教大神了 java连接jdk的问题 刚学JAVA,帮推荐几个学习JAVA的好网站 一个lastIndexOf的用法题, 请高手解决
这个不光是不显示。也会释放资源啊。。怎么会不管用呢,我们一直都这么用啊
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)是手动关闭框架时的响应动作,用于包含多哥框架集中,关了其中一个框架程序不会退出! 其实,这个方法也是隐藏框架.隐藏框架就可以了,你非要关做什么?退一步dispose()方法够用了.
if (operation != DO_NOTHING_ON_CLOSE &&
operation != HIDE_ON_CLOSE &&
operation != DISPOSE_ON_CLOSE &&
operation != EXIT_ON_CLOSE) {
throw new IllegalArgumentException("defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE");
}
if (this.defaultCloseOperation != operation) {
if (operation == EXIT_ON_CLOSE) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkExit(0);
}
}
int oldValue = this.defaultCloseOperation;
this.defaultCloseOperation = operation;
firePropertyChange("defaultCloseOperation", oldValue, operation);
}
}
/////////////////////////////////////////////////////////
public void checkExit(int status) {
checkPermission(new RuntimePermission("exitVM"));
}
/////////////////////////////////////////////////////////
operation == EXIT_ON_CLOSE 时,直接都退出 虚拟机了 难道还只是隐藏?
就这样
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
加这监听,当点激"X"时就会关闭窗口
也可以用new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
另写一个事件触发关闭窗口
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
点激button关闭窗口