用Java开发C/S应用(五):swt中关闭窗体时添加确认事件

编写一个shellClosed事件,代码如下:

        shell.addShellListener(new ShellAdapter() {
            
public void shellClosed(final ShellEvent e) {
                MessageBox messageBox 
= new MessageBox(shell,
                        SWT.ICON_WARNING 
| SWT.OK | SWT.CANCEL);
                messageBox.setText(
"确定");
                messageBox.setMessage(
"你确定要退出吗?");
                
int rc = messageBox.open();
                
if (rc == SWT.CANCEL) {
                    e.doit 
= false;
                }
            }
        });

 

e.doit 是指操作是否被允许。

posted @ 2009-07-18 15:06  魔豆  阅读(2145)  评论(0编辑  收藏  举报