The source is given to you in a .jar file. Your JDK should have included a jar extractor. These are typically invoked as
jar xvf {file}
We have not covered packages very explicitly but they are in the book and
quite simple once you get the idea. The code you were given is placed in
the package named cmpt318
. In order to have your compiler and
runtime environment find the .class
files and definitions, you
may have to instruct them where to find them.
The "where to find them" is actually JDK/JRE implementation dependent
(except for when they've been placed in .jar files). Most implementations,
however, map package hierarchies to directory hierarchies. Thus in order
to load the class cmpt318.ResultsModel
you would need to have
the file cmpt318/ResultsModel.class
in your
CLASSPATH
or search directory. So if you include the current
directory (i.e. ".") in your search path then
the class for cmpt318.ResultsModel
will be found if your current
directory is the directory containing the directory
cmpt318
(you may need to re-read this sentence repeatedly
before it makes sense).
You should consult your own compiler/JRE if you cannot get compilation or running working properly. You may have to package your .class files into a .jar file first.
The ResultsModel.setQuery()
has a parameter indicating whether
the applet is being served from its normal network location. This should
ease testing the applet locally (using appletviewer or reading your class
files from disk), since dummy values can be used instead of actually trying
to connect to AltaVista (which would slow things down anyway).
The file local-test.html
(included in the source .jar file given to you)
may help you in your local testing.
Normal browser security rules for applets are that applets should not be able to access any Internet address other than the one that served the applet. Some browsers (apparent Explorer is one of them) will allow applets loaded from local file systems unlimited host access. So far as I know all versions of Netscape do not allow this relaxation in applet security for applets loaded from file systems (except as noted below).
To test your code using "live" data there are two potential routes you may take:
ResultsModel.class
(and any other
associated .class files) in your browser's CLASSPATH (or java directory).
You can then point your browser to
"http://www.cs.sfu.ca/CC/318/walenste/assign/a3/test/query.html".
This page serves you a compiled version of the exact same applet code
as was given to you,
except its .jar file is missing the .class for
ResultsModel
. Most browsers will then load the
definitions for ResultsModel
from your local disk. You
will probably not be able to use a simple applet viewer in this
case since they usually do not deal with the password protection
required (you get security violations).
It is possible that both of these methods fail for you, however all installations I've checked have worked using at least one of these methods. Note that you do not need to test your solution with live data since you can quite easily simulate network latencies by generating fake data with random delays, however doing final testing with network data is frequently entertaining.