carbidecpp22devenv/configuration/org.eclipse.osgi/bundles/121/1/.cp/cheatsheets/HelloWorldSWT.xml
author cawthron
Fri, 04 Dec 2009 10:01:33 -0600
changeset 5 684bf18fdedf
permissions -rw-r--r--
add files for RCL_2_2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     1
<?xml version="1.0" encoding="UTF-8"?>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     2
<cheatsheet title="Create a Hello World SWT application">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     3
   <intro href="/org.eclipse.platform.doc.user/reference/ref-cheatsheets.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     4
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     5
         This cheat sheet shows you how to create a &quot;Hello World&quot; application
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     6
			that uses the Standard Widget Toolkit (SWT). The application will
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     7
			simply display an empty window to the user.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     8
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
     9
			If you need help at any step, click the (?) to the right. Let&apos;s get
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    10
			started!
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    11
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    12
   </intro>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    13
   <item title="Open the Java perspective" dialog="true" skip="false" href="/org.eclipse.platform.doc.user/concepts/concepts-4.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    14
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    15
         If you&apos;re not already in the Java perspective, in the main menu
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    16
			select <b>Window</b> &gt; <b>Open Perspective</b> &gt; <b>Java</b>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    17
			or click on the &quot;Click to Perform&quot; link below.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    18
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    19
      <command serialization="org.eclipse.ui.perspectives.showPerspective(org.eclipse.ui.perspectives.showPerspective.perspectiveId=org.eclipse.jdt.ui.JavaPerspective)" required="false" translate="">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    20
      </command>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    21
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    22
   <item title="Download SWT standalone" dialog="true" skip="false" href="/org.eclipse.platform.doc.isv/guide/swt.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    23
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    24
         Open your Web browser to http://download.eclipse.org/eclipse/downloads/,
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    25
			select the latest release build, and find the <b>SWT Binary and Source</b>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    26
			download.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    27
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    28
			Save the file to your disk; you do not need to extract the archive.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    29
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    30
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    31
   <item title="Import the SWT project" dialog="true" skip="false" href="/org.eclipse.platform.doc.user/tasks/tasks-importproject.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    32
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    33
         Import the SWT project from the main menu via File &gt; Import...,
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    34
			and select <b>Existing Projects into Workspace</b>. Specify the
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    35
			<b>archive</b> file you downloaded and click <b>Finish</b>.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    36
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    37
			This will create the org.eclipse.swt project which we will need
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    38
			to compile and run the application.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    39
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    40
      <command serialization="org.eclipse.ui.file.import(importWizardId=org.eclipse.ui.wizards.import.ExternalProject)" required="false" translate="">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    41
      </command>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    42
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    43
   <item title="Create a Java project" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/concepts/concepts-3.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    44
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    45
         Now we need a project to store our own source code. In the main
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    46
			toolbar, click on the <b>New Java Project</b> button, or click on
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    47
			the link below. Enter <b>HelloWorldSWT</b> for the project name,
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    48
			then click <b>Finish</b>.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    49
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    50
      <command serialization="org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)" required="false" translate="">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    51
      </command>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    52
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    53
   <item title="Configure the Java project" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/reference/ref-123.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    54
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    55
         Since our project requires SWT, we need to specify this in the
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    56
			project properties. Right-click on the project and select
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    57
			<b>Properties</b>.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    58
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    59
			In the <b>Java Build Path</b> page open the <b>Projects</b> tab,
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    60
			add the org.eclipse.swt project, then click <b>OK</b>.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    61
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    62
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    63
   <item title="Create a class" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/gettingStarted/qs-9.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    64
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    65
         The next step is to create a new class. In the main toolbar,
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    66
			click on the <b>New Java Class</b> button (or the link below).
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    67
			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
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    68
			create the <b>main()</b> method, then click <b>Finish</b>.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    69
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    70
			The Java editor will automatically open showing your new class.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    71
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    72
      <command serialization="org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.NewClassCreationWizard)" required="false" translate="">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    73
      </command>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    74
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    75
   <item title="Write the Java code" dialog="true" skip="false" href="/org.eclipse.platform.doc.isv/guide/swt_widgets.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    76
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    77
         In the Java editor, enter the following Java code in the
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    78
			<b>main()</b> method:<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    79
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    80
			Display display = new Display();<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    81
			Shell shell = new Shell(display);<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    82
			shell.setText(&quot;Hello world!&quot;);<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    83
			shell.open();<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    84
			while (!shell.isDisposed()) {<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    85
			if (!display.readAndDispatch()) display.sleep();<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    86
			}<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    87
			display.dispose();<br/> 
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    88
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    89
			You will get <b>compile errors</b>. Right click in the Java editor
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    90
			and select Source &gt; Organize Imports, then <b>save</b> your
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    91
			changes.
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    92
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    93
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    94
   <item title="Run your Java application" dialog="true" skip="false" href="/org.eclipse.jdt.doc.user/gettingStarted/qs-12.htm">
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    95
      <description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    96
         To <b>run</b> your application, right-click on your class in the
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    97
			Package Explorer and select <b>Run As</b> &gt; <b>Java
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    98
			Application</b>. A new empty window should appear with the
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
    99
			title &quot;Hello world!&quot;.<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   100
			<br/>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   101
			Congratulations! You have successfully created a Hello World SWT
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   102
			application!
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   103
      </description>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   104
   </item>
684bf18fdedf add files for RCL_2_2
cawthron
parents:
diff changeset
   105
</cheatsheet>