Java Reference
In-Depth Information
ErrorMsg myErrorMsg2 = new ErrorMsg ();
myErrorMsg2.setErrorMsg ("Some Text for #2");
tempMsg = myErrorMsg2.getErrorMsg ();
System.out.println (tempMsg);
Some New Text for #2
To show that two unique objects of the same type exist in HelloWorld,
you printed out the data contained in both objects. The data associated with
myErrorMsg2 contained “Some Text for #2,” and the data associated with myEr-
rorMsg contained “Some New Text.”
tempMsg = myErrorMsg2.getErrorMsg ();
System.out.println (tempMsg);
tempMsg = myErrorMsg.getErrorMsg ();
System.out.println (tempMsg);
Some New Text for #2
Some New Text
The applet versions of HelloWorld performed much the same as did the appli-
cation versions. HelloWorld, the applet, created an instance of ErrorMsg , stored
some text in it, and then printed the text. Instead of printing to standard out,
you used the Graphics class to print to a graphical window:
System.out.println (tempMsg); » becomes «
g.drawString (tempMsg, 5, 35);
Hello applet World!
In the SDK applet exercise, this drawString statement causes no data to be
displayed.
You were able to simply use the existing version of ErrorMsg in the applets. That
is, you did not need to create two versions of ErrorMsg , one for the application
and one for the applet.
You did need to instruct the compile environment where to look for the
ErrorMsg class when it was not part of the current directory. You used the
CLASSPATH argument (or project setting) to inform the compile environ-
ment of the directory that contained ErrorMsg.class.
In the case of the SDK, you also needed to inform the execution environment
(APPLETVIEWER.EXE) where it should look for the ErrorMsg class.
Search WWH ::




Custom Search