使用代码关闭java框架
可能的重复:
如何以编程方式关闭 JFrame
我正在使用 JFrame 开发 java GUI。我想关闭 GUI 框架并通过代码将其处理掉。 我已经实现:
topFrame.addWindowListener(new WindowListener()
{
public void windowClosing(WindowEvent e)
{
emsClient.close();
}
public void windowOpened(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
});`
如何调用 windowClosing 事件?或者还有其他办法吗?
Possible Duplicate:
How to programmatically close a JFrame
I am developing a java GUI using JFrame. I want to close the GUI frame and dispose it off through code.
I have implemented :
topFrame.addWindowListener(new WindowListener()
{
public void windowClosing(WindowEvent e)
{
emsClient.close();
}
public void windowOpened(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
});`
How can I invoke the windowClosing event?? Or is there some other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将以编程方式触发窗口关闭事件:
如果你想关闭框架,你需要调用:
This will programmatically trigger the window closing event:
If you want to close the frame you need to call:
调用
dispose()
方法怎么样?How about invoking
dispose()
method?你需要这个:
你可以在构造函数中添加该行(不要忘记它)。
You need this:
You can add that line in the constructor(Dont forget it).