jdesktop java,Java jdesktop FrameView的windowClosing事件?

I am trying to write a GUI application using NetBeans, and I am getting increasingly tired of it..

I constructed a "Java Desktop Application" using NetBeans. It creates the main form as a org.jdesktop.application.FrameView descendent. I would like to know what is the proper way to add some code that is executed when the form is closed.

My current attempt so far is to add a WindowAdapter object using getFrame().addWindowListener in the constructor, which doesn't work. Because you can't call getFrame while the frame is not constructed yet. And I can't see it as an event somewhere i the GUI builder.

解决方案

Java Desktop Application which is available in NetBeans IDE 6.9.1 is only for historical purposes and is not recommended for use in projects. The NetBeans IDE 6.9.1 also shows this warning when we try to create a new project using Java Desktop Application option.

PRtfK.png

Given that let me answer your question assuming you are still using the Swing Application Framework and you want to add a windowClosing listener to the Main Window.

When you create a Java Desktop Application you get three classes (assuming you typed DesktopApplication1 as the name of your application):

DesktopApplication1.java

DesktopApplication1AboutBox.java

DesktopApplication1View.java

To add the window closing listener, write the code in configureWindow method of the class DesktopApplication1 as follows:

@Override protected void configureWindow(java.awt.Window root) {

root.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

// write your code here

System.out.println("Window Closing");

}

});

}

with regards

Tushar Joshi, Nagpur

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值