我想用Eclipse創建一個Hello World SWT應用程序。我遵循所有的指示,最後我的程序不起作用。爲什麼我的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)
有誰知道我怎麼能檢查什麼是錯的?
當我替換「import org.eclipse.swt.widgets.Shell;」通過「org.eclipse.swt.widgets.Display」,Eclipse寫道我有一些衝突。我已經刪除了我的代碼的第一行(import gnu.gcj.xlib.Display;)。然後當我嘗試運行我的程序時,我仍然有一些錯誤消息: 線程「main」中的異常java.lang.Error:未解決的編譯問題: \t Shell無法解析爲某個類型 \t Shell無法解析爲類型 at HelloWorldSWT.main(HelloWorldSWT.java:12) – Roman
您必須讓導入到'org.eclipse.swt.widgets.Shell'並添加導入'org.eclipse.swt.widgets.Display'。 –