gpt4 book ai didi

java - 为什么我的 SWT 应用程序无法运行?

转载 作者:行者123 更新时间:2023-12-01 07:16:00 25 4
gpt4 key购买 nike

我正在尝试使用 Eclipse 创建 Hello World SWT 应用程序。我按照所有说明进行操作,但最终我的程序无法运行。

这是我的代码:

import gnu.gcj.xlib.Display;
import org.eclipse.swt.widgets.Shell;


public class HelloWorldSWT {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Hello world!");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

}

这是我的错误消息:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The constructor Shell(Display) is undefined
The method readAndDispatch() is undefined for the type Display
The method sleep() is undefined for the type Display
The method dispose() is undefined for the type Display

at HelloWorldSWT.main(HelloWorldSWT.java:13)

有人知道我如何检查问题所在吗?

最佳答案

我认为您导入了错误的 Display 类。正确的应该是

org.eclipse.swt.widgets.Display

关于java - 为什么我的 SWT 应用程序无法运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2272967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com