Java Reference
In-Depth Information
If you chose the first solution, go to the rear of the class. If you chose the sec-
ond, congratulations! You are well on your way to becoming an object-oriented
programmer! The primary objective when you create a class is to have other pro-
grams reuse that class. This objective is not met when a class is copied, so make sure
to always resist that temptation.
The SDK Java development environment can use a variety of mechanisms to
find the proper class files. You will cover them all eventually, but the simplest one
to use right now is the CLASSPATH argument. This argument lists directory names
the Java compiler should search in order to find any required classes.
5. Tell the Java compiler where the ErrorMsg class is by adding the CLASS-
PATH argument to the java compile statement in your command window:
javac -classpath c:\java4cobol HelloWorld.java
It should compile successfully now.
6. Now run your new HelloWorld applet. You will need to set the CLASS-
PATH argument when you run it as follows:
appletviewer -J-classpath -J.;c:/java4cobol HelloWorld.html
The syntax for the classpath includes an initial period, followed by a semicolon.
This tells the appletviewer to search in the current directory “.” and then in the
c:\java4cobol directory for all classes.
Experiment with this applet as well. You can make the changes in the text
editor and then recompile the applet in the command window.
7. Add the following lines to the end of your HelloWorld.java source file (i.e.,
immediately after the last g.drawString statement).
// Create a new instance of the ErrorMsg class.
ErrorMsg myErrorMsg2 = new ErrorMsg ();
// Set the text item to some text String, and print its contents.
myErrorMsg2.setErrorMsg ("Some Text for #2");
tempMsg = myErrorMsg2.getErrorMsg ();
g.drawString (tempMsg, 5, 75);
// Print the text item in the original object.
tempMsg = myErrorMsg.getErrorMsg ();
g.drawString (tempMsg, 5, 85);
Search WWH ::




Custom Search