FrameView窗口关闭消息无法截取

yakai 2013-03-02 04:18:16
窗口关闭,程序退出时想做一点收尾动作,发现窗口关闭时不仅截获不了消息,甚至程序就没有真正退出,是不是FrameView本身就有缺陷啊,进程都无法正常关闭?求解释,求截获窗口关闭消息,求窗口关闭时应用如何正彻底退出。


package TimingApp;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

public class TimingApp extends SingleFrameApplication {
@Override protected void startup() {
doShutDownWork();
show(new TimingView(this));
}
@Override protected void configureWindow(java.awt.Window root) {
}
public static TimingApp getApplication() {
return Application.getInstance(TimingApp.class);
}
private void doShutDownWork() {
Runtime.getRuntime().addShutdownHook(new Thread() {

public void run() {
System.out.println("Tell me where to stop");
}
});
}
public static void main(String[] args) {
launch(TimingApp.class, args);
}
}

package TimingApp;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;

/**
*
* @author Administrator
*/
public class TimingView extends FrameView {
public TimingView(SingleFrameApplication app) {
super(app);
initComponents();
JFrame mainFrame = TimingApp.getApplication().getMainFrame();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

}

@SuppressWarnings("unchecked")
private void initComponents() {
mainPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
mainPanel.setName("mainPanel");
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(TimingApp.class).getContext().getResourceMap(TimingView.class);
jLabel1.setText(resourceMap.getString("jLabel1.text"));
jLabel1.setName("jLabel1");
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(168, 168, 168)
.addComponent(jLabel1)
.addContainerGap(190, Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(125, 125, 125)
.addComponent(jLabel1)
.addContainerGap(160, Short.MAX_VALUE))
);

setComponent(mainPanel);
}

private javax.swing.JLabel jLabel1;
private javax.swing.JPanel mainPanel;

}



调试状态下应用窗口关闭后暂停,进程状态如下:
...全文
132 点赞 收藏 1
写回复
1 条回复
yakai 2013年03月02日
需要用到Netbeans的两个库: swing-worker-1.1.jar和appframework-1.0.3.jar
回复 点赞
发动态
发帖子
Java SE
创建于2007-09-28

3.4w+

社区成员

30.7w+

社区内容

Java 2 Standard Edition
社区公告
暂无公告