views:

161

answers:

1

I am trying to create a Hello World SWT application using Eclipse. I follow all instructions and in the end my program does not work.

This is my code:

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();
    }

}

And this is my error messages:

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)

Does anybody know how I can check what is wrong?

+6  A: 

I think you're importing a wrong Display class. The right one should be

org.eclipse.swt.widgets.Display
Marek R.
When I replace "import org.eclipse.swt.widgets.Shell;" by "org.eclipse.swt.widgets.Display", the Eclipse writes me that I have some conflicts. The I have removed the first line of my code (import gnu.gcj.xlib.Display;). Then when I try to run my program I still have some error messages:Exception in thread "main" java.lang.Error: Unresolved compilation problems: Shell cannot be resolved to a type Shell cannot be resolved to a type at HelloWorldSWT.main(HelloWorldSWT.java:12)
Roman
You must let the import to `org.eclipse.swt.widgets.Shell` and add the import `org.eclipse.swt.widgets.Display`.
True Soft