Topic: 如何退出整个程序?

  Print this page

1.如何退出整个程序? Copy to clipboard
Posted by: linkie
Posted on: 2003-12-08 19:00

当使用鼠标点击主窗口标题栏的关闭按钮(“X”)时,如果用类似下面的语句,我发现实际上程序并没有真正退出。
......
while (!display.isDispose()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}

display.dispose();

请问该如何解决这个问题呢?也就是说,如何去捕获这个事件(包括利用系统热键(Ctrl + F4)去关闭它),然后正确地退出整个应用程序呢?

如果在界面上放置一个Button("btnExit"),然后给这个Button添加一个SelectionLister就能够正常退出程序:
......

Button btnExit = new Button(shell, SWT.PUSH);
btnExit.setText("&Exit");
......

btnExit.addSelectioinListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
display.dispose();
}
});

请各位前辈指点迷津!先行谢过!

2.Re:如何退出整个程序? [Re: linkie] Copy to clipboard
Posted by: WhisperQQ
Posted on: 2004-01-05 16:20

你这句写错了!应该是:
while (!shell.isDisposed()) {
...
}

3.To WhisperQQ [Re: linkie] Copy to clipboard
Posted by: linkie
Posted on: 2004-01-06 09:30

Thank you for your enthusiastic answer. Happy new year.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923