Java Reference
In-Depth Information
HelloWorld Java source file. Save this change by pressing CTRL-S or by using the
File > Save menu path. You should see the red X boxes disappear as Eclipse re-
compiles the applet.HelloWorld class.
Now you can run the HelloWorld applet. Select the Run > Run As > Java Ap-
plet menu choice. You should see the HelloWorld applet window pop up, with the
“Hello applet World!” message in the dialog. Exit the window, and try changing the
message to “Hello applet World in Eclipse!”
For the final exercise, you will deal with a more complicated example of refac-
toring, using the exercises from Chapter 3.
Create a new Java project in Eclipse and call it “Chapter3.” Then, import the
files from the Chapter 3 exercises on the CD-ROM. In the Filter Types dialog in the
Import function, add *.html and *.java to your choices so that you get the java
source and the HelloWorld.html file, which you will need to run the applet. Make
sure to point the target of the import to Chapter3\src.
You should see the familiar red X box in the Package Explorer for Chapter3.
Before you fix that problem, you want to organize this project a little differently.
You want to move the two classes in the default package to the package named
java4cobol.
In the Package Explorer, open the Chapter3\src\default package directory. You
should see two Java classes listed, HelloWorld and ErrorMsg . Using the Shift key and
the left mouse button, select both of those classes. Then, using the right mouse but-
ton, choose Refactor from the menu list. Finally, select the Move option from the
refactor choices, as shown in Figure 17.9.
On the next dialog, titled Move, click the Create Package button. Enter
java4cobol as the package name in the next dialog, and click Finish. Then click OK
in the Move dialog. You may see a dialog indicating some potential matches have
been found. If you do, click the Continue button.
In the Package Explorer, you can see that Eclipse has moved the two selected
classes from the default package to the package named java4cobol. Open up that
new package, and double-click on the ErrorMsg class. You can see the new package
defintion inserted by Eclipse into the ErrorMsg java source file. Eclipse has also
moved the java files source from the default package location to the java4cobol di-
rectory. You can check this by looking at the directory C:\java4cobol\work-
space\Chapter3\src\java4cobol on the file system.
Next, you will fix the two problems in the applet\HelloWorld class. Open the
source for Chapter3\applet\HelloWorld in the source edit window by finding that
class in the Package Explorer and double-clicking on it.
Search WWH ::




Custom Search