Step 9.1: Workbench cleanup


Step 9.1: Workbench cleanup

click to expand

q 9.1(a) Close HelloWorld2.java by clicking on the X in the editor tab.

click to expand
Figure 9.1: Close HelloWorld2.java.

q 9.1(b) Close HelloWorld.java by clicking on the X in the editor tab.

click to expand
Figure 9.2: Close HelloWorld.java.

Note  

The Console view shows the current console, which contains the results of the last debug run. To clear the current console, click on the "eraser" icon (the top icon on the left). The console view keeps the contents of all your recent runs. You can access a list of all console views by clicking the down arrow next to the running man icon (left of the eraser).

q 9.1(c) Clear the Console view.

click to expand
Figure 9.3: Clear the console with the eraser icon.

This will leave you with a nice, clean workbench like the one in Figure 9.4.

click to expand
Figure 9.4: The workbench, all cleaned up and ready to go.



Step 9.2: Create a new project

click to expand

The easiest way to avoid clutter is to segregate programs into projects. In this case, we'll create a new project called SWT, since we'll be concentrating on SWT programming. In previous steps, I had you add a new project by using the popup menu from the navigator view. In this step, I'll show you an alternative method: the File/New/Project... option. The File menu has a New submenu, and the New submenu has a Project... option.

q 9.2(a) From the Eclipse main menu bar, select File/New/Project ...

click to expand
Figure 9.5: Adding a new project using the File menu, New submenu, Project... option.

q 9.2(b) Make sure Java and Java Project are selected and click Next.

click to expand
Figure 9.6: Adding a new Java Project.

q 9.2(c) Enter SWT in the Project name field and select Finish.

click to expand
Figure 9.7: Enter the project name, SWT, and select the Finish button.

You will have added a new project, as shown in Figure 9.8.

click to expand
Figure 9.8: The new SWT project!

q 9.2(d) Expand the SWT project.

click to expand
Figure 9.9: Use the plus sign to expand the SWT project.

You'll see a JAR file in your project. Roll your cursor over it as shown in Figure 9.10, and you'll see that it's the same runtime JAR file as in the Hello project.

click to expand
Figure 9.10: Rolling your cursor over the JAR file shows that it is the same runtime file as in the Hello project.



Step 9.3: Add a new class, HelloSWT

click to expand

Like most third-party packages, the SWT packages are in a JAR file. SWT is a little different from other packages, though, in that it is not "100% Pure Java," meaning that there is at least one component to the SWT package that is not contained in a JAR file. For SWT, this is a special file that interfaces between the Java classes and the operating system. In Windows, this is a DLL file. In this step, you'll see one way of including this (or any other) DLL in your environment. Later we'll show you a more pervasive way.

q 9.3(a) Make sure the SWT project is selected.

q 9.3(b) Right-click in the Package Explorer and select File/New/Class.

click to expand
Figure 9.11: Creating a new class using New/Class.

q 9.3(c) Make sure the Source Folder is SWT.

q 9.3(d) Leave Package blank.

q 9.3(e) Leave Enclosing type unchecked.

q 9.3(f) Enter HelloSWT in the Name field.

q 9.3(g) Make sure public is checked, abstract and final unchecked.

q 9.3(h) Leave Superclass as java.lang.Object, Interfaces blank.

q 9.3(i) Make sure public static void main(String[] args) is checked.

q 9.3(j) Leave the other two unchecked.

q 9.3(k) Select Finish.

click to expand
Figure 9.12: Setting the fields properly for a new class.

This will create a class HelloSWT in the default package (because you left Package blank) in project SWT. It will be a public class, neither abstract nor final. The class has no superclass (except for the implied superclass Object) and implements no interfaces. Finally, the IDE has been instructed to create a standard "main" method, but no other methods . That being the case, we will see the result as in Figure 9.13.

click to expand
Figure 9.13: The result of the addition of the new class HelloSWT.