When we program Java window program code, we always encounter the problem that the running window is closed but the program does not exit, so today I will introduce how to solve it.
#What should I do if the java program does not exit?
The java program does not exit because when creating the program, the line of code setDefaultCloseOperation(JFrame.EXIT-ON-CLOSE) is missing. This code means that when the user When the close button is clicked, the program exits.
The complete code is as follows:
// JFrameDemo1.java import javax.swing.*; //使用Swing类,必须引入Swing包 public class JFrameDemo1{ public staticvoid main( String args[]) { //定义一个窗体对象f,窗体名称为"一个简单窗口" Jframe f = new JFrame("一个简单窗口"); //设置窗体左上角与显示屏左上角的坐标, f.setLocation(300,300); //离显示屏上边缘300像素,里显示屏左边缘300像素 f.setSize(300,200); //设置窗体的大小为300*200像素大小 f.setResizable(false); //设置窗体是否可以调整大小,参数为布尔值 //设置窗体可见,没有该语句,窗体将不可见,此语句必须有,否则没有界面就没有如何意义了 f.setVisible( true); //用户单击窗口的关闭按钮时程序执行的操作 // ************** f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); // ************** } }
Recommended related articles and tutorials: java introductory tutorial
The above is the detailed content of What should I do if the java program does not exit?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.