package swt;import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;public class HelloWorld { /**
* @param args
*/
public static void main(String[] args) {
Display dis = new Display();
Shell shell = new Shell(dis);
shell.setText("This is my first SWT program!");
shell.setSize(200,100);
shell.open();
while (!shell.isDisposed()) {
if(dis.readAndDispatch()) {
dis.sleep();
}
dis.dispose();
} }}
为什么一运行画面就关闭了!
import org.eclipse.swt.widgets.Shell;public class HelloWorld { /**
* @param args
*/
public static void main(String[] args) {
Display dis = new Display();
Shell shell = new Shell(dis);
shell.setText("This is my first SWT program!");
shell.setSize(200,100);
shell.open();
while (!shell.isDisposed()) {
if(dis.readAndDispatch()) {
dis.sleep();
}
dis.dispose();
} }}
为什么一运行画面就关闭了!
楼主【PurpleSE】截止到2008-07-09 13:12:55的历史汇总数据(不包括此帖):
发帖的总数量:1 发帖的总分数:0 每贴平均分数:0
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:0
结贴的百分比:0.00 % 结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
应该是 :
if(!dis.readAndDispatch()) { -------------------------------------------------------------
Quietly through .....
if(dis.readAndDispatch()) {
dis.sleep();
} 问题在这里,应该是if(!dis.readAndDispatch()),否则必然是一打开就关闭啊,程序没有执行错,是你写错了
if(dis.readAndDispatch()) {
dis.sleep();
}
dis.dispose();//释放DISPLAY
}
}
} 刚刚看了写了代码,发现我错了,应该是这里错了。我给你注释了,在shell没有被释放的时候[类似没有关闭窗口],你就释放了display,所以一起来就自动退出。
Display display = Display.getDefault();
SmlShell window = new SmlShell(display, SWT.SHELL_TRIM);
window.layout();
window.open(); while(!window.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
} display.dispose();