在最后一个窗口上调用处理后,java swing程序未关闭 [英] java swing program not closing after dispose is called on last window

查看:119
本文介绍了在最后一个窗口上调用处理后,java swing程序未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前言:这是我完成的第一个真正的挥杆程序。

Preface: This is the first real swing program I have done.

我有一个挥杆程序,其中一个JButton应该退出该程序。该按钮触发this.dispose();。当我单击此JButton时,它确实使窗口完全消失,但是看着调试器,程序本身仍在运行。

I have a swing program, where one JButton is supposed to exit the program. That button triggers this.dispose();. When i click this JButton, it does make the window completely go away, but looking at the debugger, the program itself is still running.

我的主要方法仅包括:

public static void main (String[] args)
{
  java.awt.EventQueue.invokeLater(new Runnable()
  {
    public void run()
    {
      new StartupGui().setVisible(true);
    }
  });
}

我的退出按钮看起来像动作按钮:

My exit button looks like action button looks like:

private void exitButtonActionPerformed(java.awt.event.ActionEvent evt)
{
  this.dispose();
}

我也尝试过使用退出按钮:

I have also tried this for the exit button:

private void exitButtonActionPerformed(java.awt.event.ActionEvent evt)
{
  java.awt.EventQueue.invokeLater(new Runnable()
  {
    public void run()
    {
      dispose();
    }
  });
}

在按退出按钮后查看调试器,我看到以下内容(并且只有以下内容):

Looking at the debugger after i press the exit button, i see the following (and only the following):

Daemon Thread [AWT-XAWT] (running)
Thread [AWT-Shutdown] (running)
Thread [AWT-EventQueue-0] (running)
Thread [DestroyJavaVM] (running)

有人可以指出正确的方向,为什么程序在此时间后仍无法关闭吗?我已经进行了一些谷歌搜索,但到目前为止还没有到任何地方。如果您需要更多信息,请告诉我

Can anyone point me in the right direction as to why the program isn't shutting down after this point? I have done some googling but haven't gotten anywhere thus far. If you need any more information, just let me know

谢谢:)

推荐答案

因为处理()方法仅释放资源。

Because dispose() method only releases the resources.

该文档具有


注意:丢弃Java虚拟机(VM)中的最后一个可显示窗口时,VM 可以 终止。请参见 AWT线程问题有关更多信息。

Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.

您是否注意到可能

上面的链接为您提供有关自动关闭功能的详细信息。您可以阅读有关此内容的更多信息,也可以通过将 this.dispose()替换为 System.exit(0)

The link above gives you detailed information about the Auto shutdown feature. You can read more about that, or you can simply solve this by replacing this.dispose() with System.exit(0)

这篇关于在最后一个窗口上调用处理后,java swing程序未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆