网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java窗体程序关闭代码 java窗口程序运行后不能关闭

java关闭窗体的六种方法

前段时间集中精力写了两篇论文 很久没写博文了 现在继续了

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

使用JFrame的enableEvents和processWindowEvent

//Frame java

import java awt *;

import java awt event *;

import javax swing *;

public class Frame extends JFrame {

public Frame () {

enableEvents(AWTEvent WINDOW_EVENT_MASK);

this setSize(new Dimension( ));

this setTitle( Frame );

}

protected void processWindowEvent(WindowEvent e) {

super processWindowEvent(e);

if (e getID() == WindowEvent WINDOW_CLOSING) {

System exit( );

}

}

}

直接实现WindowListener接口

//Frame java

import java awt *;

import java awt event *;

public class Frame extends Frame implements WindowListener {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(this);

}

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

public void windowOpened(WindowEvent windowEvent) {  }

public void windowClosed(WindowEvent windowEvent) {  }

public void windowIconified(WindowEvent windowEvent) {  }

public void windowDeiconified(WindowEvent windowEvent) {  }

public void windowActivated(WindowEvent windowEvent) {  }

public void windowDeactivated(WindowEvent windowEvent) {  }

}

直接继承窗体适配器WindowAdapter

//Frame java

import java awt *;

import java awt event *;

public class Frame extends  WindowAdapter {

public Frame () {

Frame f=new Frame();

f setSize(new Dimension( ));

f setTitle( Frame );

f addWindowListener(this);

f setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

}

间接继承窗体适配器WindowAdapter

//Frame java

import java awt *;

import java awt event *;

public class Frame extends  Frame {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(new winAdapter());

this setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

class winAdapter extends WindowAdapter{

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

}

间接实现WindowListener接口

//Frame java

import java awt *;

import java awt event *;

public class Frame extends  Frame {

public Frame () {

this setSize(new Dimension( ));

this setTitle( Frame );

this addWindowListener(new winEventHandle());

this setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

class winEventHandle implements WindowListener {

public void windowClosing(WindowEvent windowEvent) {

System exit( );

}

public void windowOpened(WindowEvent windowEvent) {  }

public void windowClosed(WindowEvent windowEvent) {  }

public void windowIconified(WindowEvent windowEvent) {  }

public void windowDeiconified(WindowEvent windowEvent) {  }

public void windowActivated(WindowEvent windowEvent) {  }

public void windowDeactivated(WindowEvent windowEvent) {  }

}

使用Inner Class

//Frame java

import java awt *;

import java awt event *;

public class Frame {

public Frame (){

Frame f=new Frame();

f addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System exit( );

}

});

f setSize(new Dimension( ));

f setVisible(true);

}

public static void main(String[] s){

new Frame ();

}

}

Jframe的关闭方法

setDefaultCloseOperation(EXIT_ON_CLOSE);

frame的关闭方法如下

this addWindowListener(new java awt event WindowAdapter() {

public void windowClosing(java awt event WindowEvent e) {

System exit( );

}

lishixinzhi/Article/program/Java/hx/201311/27073

java程序关闭窗口代码

import java.applet.*;

import java.awt.Color;

import java.awt.Frame;

import javax.swing.JFrame;

import java.awt.event.*;

public class FirstFrame extends Frame {

public static void main(String args[]) {

FirstFrame fr = new FirstFrame("First contianer!");

fr.setSize(240, 240);

//继承JFrame的关闭窗口代码

//fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//继承Frame的

fr.addWindowListener(new WindowAdapter() {    

public void windowClosing(WindowEvent e) {        

System.exit(0);//退出系统   

}

});

fr.setVisible(true);

}

public FirstFrame(String str) {

super(str);

}

}

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

你用的 swing 吗?加上 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

或者加上窗口事件监听器:

addWindowListener(new WindowAdapter() {

public void windowClosing (WindowEvent we) {

dispose();

}

});


网页标题:java窗体程序关闭代码 java窗口程序运行后不能关闭
转载来源:http://bjjierui.cn/article/dosposi.html

其他资讯