Step 7.4: Write the code for the new class


Step 7.4: Write the code for the new class

click to expand

You may either enter the code directly into the editor or use the Import feature to import the source from the supplied CD-ROM. If you wish to enter the source yourself and get a feel for the source editor, use Option I below. Otherwise, skip ahead to Option 2.

Option 1: Source Entry

q 7.4(a) Enter the following source code as your main() method.

 System.out.println("Hello World!"); System.exit(0); 
click to expand
Figure 7.11: Source code entered into the editor pane.

q 7.4(b) Right-click in the editor pane and select Save.

click to expand
Figure 7.12: Right-click in the editor pane and select Save to save the code.

Another option is just to press Ctrl-S. At this point, you can skip ahead to Step 7.5. However, you might want to execute Option 2 anyway. This will import the code from the CD-ROM and overwrite the code you just entered. It will look exactly the same as what you typed in except for the author name , and you'll learn how to use the Import feature, which I'm sure you'll be using in the future.

Option 2: Importing Source from CD

Importing is quite easy. The only part that can get a little confusing is the relationship between folders and packages. When you are importing from a file system, you must be certain to import from the correct point in the file tree. To make it easy for this book, I have located the source for each step in a folder named for that step, as you are about to see.

q 7.4(c) Insert the included CD-ROM into your CD-ROM drive.

q 7.4(d) Right-click on the Hello project and select Import ...

click to expand
Figure 7.13: Use the popup menu in the Package Explorer to import a file into the Hello project.

The Import wizard gives you several options for your import source. Since your source is in a folder on the CD-ROM, you'll use the File system option.

q 7.4(e) Select File system in the Import wizard and click Next.

click to expand
Figure 7.14: Select File system as the source for the import.

Now you need to specify the location of the files. All source for this step is located on the CD-ROM in a folder called Source, in a subfolder called Step 7, so specify R:\Source\Step 7, where R is the letter of the CD-ROM drive where you loaded the disk. In Figure 7.15, the disk is loaded in the D: drive.

click to expand
Figure 7.15: Enter R ”\Source\Step 7, where R is the drive where you loaded the included CD-ROM.

q 7.4(f) Enter "R:\Source\Step 7" in the From directory field, where R is the drive letter of your CD-ROM drive, and press the Tab key.

The Tab key will cause the left pane to display an icon for the Step 7 folder. Select the Step 7 folder by clicking on it.

q 7.4(g) Left-click on the Step 7 folder.

click to expand
Figure 7.16: Select the Step 7 folder by left-clicking on it.

This will cause the contents of the Step 7 folder to appear in the right-hand pane as shown in Figure 7.17.

click to expand
Figure 7.17: The contents of the Step 7 folder will appear in the right hand pane.

Select HelloWorld.java by clicking on its checkbox.

q 7.4(h) Select HelloWorld.java and click Finish.

click to expand
Figure 7.18: Select only Hello World.Java, then click Finish.

If you also performed Option 1, you will get a confirmation dialog like the one in Figure 7.19.

click to expand
Figure 7.19: This prompt is used to be sure you really want to overwrite your source.

q 7.4(i) Click Yes on the confirmation box that pops up.

When you are done, your display should look just like the one shown in Figure 7.20. Since the source on the CD doesn't have all the fancy auto-generated comments, it'll be a little more austere than what the tool generated, as you can see.

click to expand
Figure 7.20: The workbench display after importing source code from the included CD-ROM.



Eclipse
Eclipse: Step by Step (Step-by-Step series)
ISBN: 1583470441
EAN: 2147483647
Year: 2003
Pages: 90
Authors: Joe Pluta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net