Home > Java > Javagetting Started > body text

What should I do if the java program does not exit?

angryTom
Release: 2020-02-10 11:31:38
Original
2920 people have browsed it

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?

#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);     // **************
 }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template