Java应用程序窗口关闭的六种方法

Java应用程序窗口关闭的六种方法


2024年1月24日发(作者:)

Java应用程序窗口关闭的六种方法

Java应用程序窗口关闭的六种方法:

1.使用JFrame的enableEvents和processWindowEvent

/ /

import .*;

import .*;

import .*;

public class Frame1 extends JFrame {

public Frame1() {

enableEvents(_EVENT_MASK);

e(new Dimension(400, 300));

le("Frame1");

}

protected void processWindowEvent(WindowEvent e) {

sWindowEvent(e);

if (() == _CLOSING) {

(0);

}

}

}

2.直接实现WindowListener接口

//

import .*;

import .*;

public class Frame1 extends Frame implements WindowListener {

public Frame1() {

e(new Dimension(400, 300));

le("Frame1");

dowListener(this);

}

public void windowClosing(WindowEventwindowEvent) {

(0);

}

public void windowOpened(WindowEventwindowEvent) { }

public void windowClosed(WindowEventwindowEvent) { }

public void windowIconified(WindowEventwindowEvent) { }

public void windowDeiconified(WindowEventwindowEvent) { }

public void windowActivated(WindowEventwindowEvent) { }

public void windowDeactivated(WindowEventwindowEvent) { }

}

3.直接继承窗体适配器WindowAdapter

//

import .*;

import .*;

public class Frame1 extends WindowAdapter {

public Frame1() {

Frame f=new Frame();

e(new Dimension(400, 300));

le("Frame1");

dowListener(this);

ible(true);

}

public static void main(String[] s){

new Frame1();

}

public void windowClosing(WindowEventwindowEvent) {

(0);

}

}

4.间接继承窗体适配器WindowAdapter

//

import .*;

import .*;

public class Frame1 extends Frame {

public Frame1() {

e(new Dimension(400, 300));

le("Frame1");

dowListener(new winAdapter());

ible(true);

}

public static void main(String[] s){

new Frame1();

}

}

class winAdapter extends WindowAdapter{

public void windowClosing(WindowEventwindowEvent) {

(0);

}

}

5.间接实现WindowListener接口

//

import .*;

import .*;

public class Frame1 extends Frame {

public Frame1() {

e(new Dimension(400, 300));

le("Frame1");

dowListener(new winEventHandle());

ible(true);

}

public static void main(String[] s){

new Frame1();

}

}

class winEventHandle implements WindowListener {

public void windowClosing(WindowEventwindowEvent) {

(0);

}

public void windowOpened(WindowEventwindowEvent) { }

public void windowClosed(WindowEventwindowEvent) { }

public void windowIconified(WindowEventwindowEvent) { }

public void windowDeiconified(WindowEventwindowEvent) { }

public void windowActivated(WindowEventwindowEvent) { }

public void windowDeactivated(WindowEventwindowEvent) { }

}

6.使用Inner Class

//

import .*;

import .*;

public class Frame1{

public Frame1(){

Frame f=new Frame();

dowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

(0);

}

});

e(new Dimension(400, 300));

ible(true);

}

public static void main(String[] s){

new Frame1();

}

}

Jframe的关闭方法:

setDefaultCloseOperation(EXIT_ON_CLOSE);

frame的关闭方法如下:

dowListener(new Adapter() {

public void windowClosing(Event e) {

(0);

}

});


发布者:admin,转转请注明出处:http://www.yc00.com/news/1706106155a1440908.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信