当我在 eclipse 中输入以下 Java 代码时,它返回一个错误。 Eclipse 教程告诉我这应该可行。我究竟做错了什么? This is a picture of my code 。
import org.eclipse.swt;
public class SWTHELLOWORLD{
public static void main(String[] args){
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();
}
}
当我作为 java 应用程序运行时,它返回此错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Display cannot be resolved to a type
Display cannot be resolved to a type
Shell cannot be resolved to a type
Shell cannot be resolved to a type
最佳答案
您没有导入 Display 和 Shell 类。
您应该将以下导入添加到类的顶部:
import org.eclipse.swt.widgets.Display
import org.eclipse.swt.widgets.Shell
仅导入 org.eclipse.swt
不会导入您需要的所有类。
关于java - Eclipse Java JDE 中的 SWT 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40999713/