如何正确关闭 Swing 应用程序 [英] How to Close a swing application properly

查看:61
本文介绍了如何正确关闭 Swing 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一些线程制作了一个 java swing 应用程序.当我在窗口中按下x"按钮时,所有正在运行的线程都停止并且应用程序正确关闭.但我想从 java 代码关闭应用程序.我用过 this.dispose();关闭应用程序.但是当我使用该方法时,窗口已关闭.但所有线程仍在运行.我如何正确关闭应用程序.请帮帮我.

I make a java swing application with some threads. When I pressed 'x' button in window, all running threads stopped and application close properly. But I want to close the application from java code. I used this.dispose(); for close the application. But when I used that method, window is closed. But all threads are still running. How I closed the application properly. please help me.

推荐答案

use System.exit(0); 导致 JVM 静默杀死应用程序,或者让其他线程作为 守护进程

use System.exit(0); causes JVM kills the application silently, OR make other threads as daemon

这篇关于如何正确关闭 Swing 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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