java - Eclipse Java JDE 中的 SWT 不工作

标签 java eclipse swt

当我在 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/

相关文章:

eclipse 自动完成

java - 使用SWT浏览器Widget编写桌面应用程序

java - SWT 与级联 MenuItem 加速器相关的问题

java - 渲染 Play framework 2.0.2 模板的一部分

java - 如何从java中的FileOutPutStream获取标签的图像?

java - 简单的算法。搞不定

java - google-play-services 中的 Google Wallet API 缺失

java - 将生成的源作为源文件夹添加到 Eclipse

swt - 更改 SWT 选项卡的外观

Java 的 SHA-256 有时会返回 255 位