Hello World!
It seems to me that I already seen this expression somewhere.
Well, let’s go?
First thing to know is that we need two SWT widgets to make a window appear:
- Display
- Shell
Then a loop while to tell the program to continue displaying the window until someone close it.
Now, the code.
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Helloworld {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(300, 300);
shell.setText("Hello World");
shell.open();
while(!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
display.dispose();
}
}
Right click on the HelloWorld class and run it as a Java Application.
The window is coming and displays the title Hello World.
Really easy, isn’t it?