资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java界面退出代码,java 程序退出

java中关闭当前窗口用什么代码

setDefaultCloseOperation(JFrame.EXIT_ON_CLOES)会让整个程序都退出

太仆寺网站建设公司成都创新互联公司,太仆寺网站设计制作,有大型网站制作公司丰富经验。已为太仆寺上千家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的太仆寺做网站的公司定做!

JFrame.DISPOSE_ON_CLOSE只让当前的窗口关闭而已

实现界面登陆,退出功能的java代码怎么写?

CS结构系统的退出如下:public void init() {

this.setTitle("用户登录界面");

this.add(createCenterPane());

this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);

this.setSize(new Dimension(450, 335));

this.setLocationRelativeTo(null);

// this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",

"系统提示:", JOptionPane.YES_NO_OPTION);

if (choose == JOptionPane.YES_OPTION) {

System.exit(1);

}

}

});

}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!

java关闭当前窗口代码

方法一:

类 JFrame

javax.swing.JFrame

JFrame中的方法void setDefaultCloseOperation(int)可以设置

以下为改方法的用法:

setDefaultCloseOperation

public void setDefaultCloseOperation(int operation)设置用户在此窗体上发起

"close" 时默认执行的操作。必须指定以下选项之一:

DO_NOTHING_ON_CLOSE(在 WindowConstants 中定义):不执行任何操作;要求程序在已注册的

WindowListener 对象的 windowClosing 方法中处理该操作。

HIDE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册的 WindowListener

对象后自动隐藏该窗体。

DISPOSE_ON_CLOSE(在 WindowConstants 中定义):调用任意已注册 WindowListener

的对象后自动隐藏并释放该窗体。

EXIT_ON_CLOSE(在 JFrame 中定义):使用 System exit

方法退出应用程序。仅在应用程序中使用。

默认情况下,该值被设置为 HIDE_ON_CLOSE。更改此属性的值将导致激发属性更改事件,其属性名称为

"defaultCloseOperation"。

注:当 Java 虚拟机 (VM) 中最后一个可显示窗口被释放后,虚拟机可能会终止

要实现你说的,应该采用

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

方法二:

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

public class Test extends JFrame {

public Test(){

this.setTitle("title");

this.setSize(300,200);

this.setLocation(100,100);

//设置关闭时什么也不做

this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

//监听关闭按钮的点击操作

this.addWindowListener(new WindowAdapter(){

//new 一个WindowAdapter 类 重写windowClosing方法

//WindowAdapter是个适配器类 具体看jdk的帮助文档

public void windowClosing(WindowEvent e) {

//这里写对话框

if(JOptionPane.showConfirmDialog(null,

"退出","提

示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){

System.exit(0);

}

}

});

this.setVisible(true);

}

public static void main(String[] args) {

new Test();

}

}

实现 界面登陆 退出 功能的java代码杂写

CS结构系统的退出如下:public void init() {

this.setTitle("用户登录界面");

this.add(createCenterPane());

this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);

this.setSize(new Dimension(450, 335));

this.setLocationRelativeTo(null);

// this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

int choose = JOptionPane.showConfirmDialog(null, "是否要退出登录界面?",

"系统提示:", JOptionPane.YES_NO_OPTION);

if (choose == JOptionPane.YES_OPTION) {

System.exit(1);

}

}

});

}其中this为JFrame对象。BS结构的退出直接用windows.close()方法就行了!


网页标题:java界面退出代码,java 程序退出
链接分享:http://cdkjz.cn/article/hspeop.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220