簡體   English   中英

Eclipse Java JDE中的SWT無法正常工作

[英]SWT in eclipse Java JDE not working

當我將以下Java代碼輸入eclipse時,它將返回錯誤。 蝕教程告訴我這應該起作用。 我究竟做錯了什么? 這是我的代碼的圖片

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不會導入您需要的所有類。

你用過

public static void main (Strings[] args)

而正確的放置方式是

public static void main (String [] args)

請注意,它是String,結尾沒有's'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM