This cheat sheet shows how to create a "Hello World" application that uses a set of standard widgets (SWTs). The application will simply show a blank window to the user. If you need help in any, press the button (?) To the right. Let it begin!
If you are not already in the Java perspective, in the main menu, select Window> Open Perspective> Java or click "Click to Run", the link below.
Open the import wizard in the main menu using File> Import ... and choose Plug-in Development> Plugins and Snippets. Click Next. On the Import Plugins and Snippets Page, select Import from: Active Target Platform. Plugins and snippets to import: select from all the plugins and snippets found in the specified location. Import as: Projects with source folders. Click Next. On the Selection page, add org.eclipse.swt. {Platform}. {Os}. {Arch} (ex: org.eclipse.swt.win32.win32.x86 for win32) to the plugins and snippets to import : list. Click βFinish." This will create org.eclipse.swt. {platform}. {os}. {arch}, which we will need to compile and run the application.
Now we need a project to store our own source code. Basically a toolbar, click the "Create Java Project" button or click the link below. Enter HelloWorldSWT for the project name, then click Finish.
Since SWT is required for our project, we must indicate this in the project properties. Right-click the project and select Properties. in On the Java Build Path Path page, open the Projects tab, add org.eclipse.swt. {platform}. {os}. {arch}, then click OK.
The next step is to create a new class. On the main toolbar, click the New Java Class button (or the link below). If not already specified, select HelloWorldSWT / src as the source folder. Log in HelloWorldSWT for the class name and check the box to create main (), then click Finish. Java editor automatically open its new class.
In the Java editor, enter the following Java code in the main () method: 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 (); You will get compilation errors. Right-click in the Java editor and choose Source> Organize Import, then save the changes.
To start the application, right-click your class in the Explorer package and select Run As> Java Application. A new blank window should appear with the inscription "Hello world!". Congratulations! Do you have successfully created the Hello World SWT application!
But when I tried to run the program, instead of displaying a blank screen as expected, it reset it in the terminal:
I am using an x64 system with installed 64-bit Eclipse and 32-bit and 64-bit versions of Java (I think). Please help. Thanks.