carbidecpp22devenv/configuration/org.eclipse.osgi/bundles/121/1/.cp/cheatsheets/HelloWorldSWT.xml
<?xml version="1.0" encoding="UTF-8"?>
<cheatsheet title="Create a Hello World SWT application">
<intro href="/org.eclipse.platform.doc.user/reference/ref-cheatsheets.htm">
<description>
This cheat sheet shows you how to create a "Hello World" application
that uses the Standard Widget Toolkit (SWT). The application will
simply display an empty window to the user.<br/>
<br/>
If you need help at any step, click the (?) to the right. Let's get
started!
</description>
</intro>
<item title="Open the Java perspective" dialog="true" skip="false" href="/org.eclipse.platform.doc.user/concepts/concepts-4.htm">
<description>
If you're not already in the Java perspective, in the main menu
select <b>Window</b> > <b>Open Perspective</b> > <b>Java</b>
or click on the "Click to Perform" link below.
</description>
<command serialization="org.eclipse.ui.perspectives.showPerspective(org.eclipse.ui.perspectives.showPerspective.perspectiveId=org.eclipse.jdt.ui.JavaPerspective)" required="false" translate="">
</command>
</item>
<item title="Download SWT standalone" dialog="true" skip="false" href="/org.eclipse.platform.doc.isv/guide/swt.htm">
<description>
Open your Web browser to http://download.eclipse.org/eclipse/downloads/,
select the latest release build, and find the <b>SWT Binary and Source</b>
download.<br/>
<br/>
Save the file to your disk; you do not need to extract the archive.
</description>
</item>
<item title="Import the SWT project" dialog="true" skip="false" href="/org.eclipse.platform.doc.user/tasks/tasks-importproject.htm">
<description>
Import the SWT project from the main menu via File > Import...,
and select <b>Existing Projects into Workspace</b>. Specify the
<b>archive</b> file you downloaded and click <b>Finish</b>.<br/>
<br/>
This will create the org.eclipse.swt project which we will need
to compile and run the application.
</description>
<command serialization="org.eclipse.ui.file.import(importWizardId=org.eclipse.ui.wizards.import.ExternalProject)" required="false" translate="">
</command>
</item>
<item title="Create a Java project" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/concepts/concepts-3.htm">
<description>
Now we need a project to store our own source code. In the main
toolbar, click on the <b>New Java Project</b> button, or click on
the link below. Enter <b>HelloWorldSWT</b> for the project name,
then click <b>Finish</b>.
</description>
<command serialization="org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)" required="false" translate="">
</command>
</item>
<item title="Configure the Java project" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/reference/ref-123.htm">
<description>
Since our project requires SWT, we need to specify this in the
project properties. Right-click on the project and select
<b>Properties</b>.<br/>
<br/>
In the <b>Java Build Path</b> page open the <b>Projects</b> tab,
add the org.eclipse.swt project, then click <b>OK</b>.
</description>
</item>
<item title="Create a class" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/gettingStarted/qs-9.htm">
<description>
The next step is to create a new class. In the main toolbar,
click on the <b>New Java Class</b> button (or the link below).
If not already specified, select <b>HelloWorldSWT/src</b> as the source folder. Enter <b>HelloWorldSWT</b> for the class name and select the checkbox to
create the <b>main()</b> method, then click <b>Finish</b>.<br/>
<br/>
The Java editor will automatically open showing your new class.
</description>
<command serialization="org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.NewClassCreationWizard)" required="false" translate="">
</command>
</item>
<item title="Write the Java code" dialog="true" skip="false" href="/org.eclipse.platform.doc.isv/guide/swt_widgets.htm">
<description>
In the Java editor, enter the following Java code in the
<b>main()</b> method:<br/>
<br/>
Display display = new Display();<br/>
Shell shell = new Shell(display);<br/>
shell.setText("Hello world!");<br/>
shell.open();<br/>
while (!shell.isDisposed()) {<br/>
if (!display.readAndDispatch()) display.sleep();<br/>
}<br/>
display.dispose();<br/>
<br/>
You will get <b>compile errors</b>. Right click in the Java editor
and select Source > Organize Imports, then <b>save</b> your
changes.
</description>
</item>
<item title="Run your Java application" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/gettingStarted/qs-12.htm">
<description>
To <b>run</b> your application, right-click on your class in the
Package Explorer and select <b>Run As</b> > <b>Java
Application</b>. A new empty window should appear with the
title "Hello world!".<br/>
<br/>
Congratulations! You have successfully created a Hello World SWT
application!
</description>
</item>
</cheatsheet>