How to compile and run with the Keyboard class.
The Keyboard class from the text can be useful for IO in the early stages of
programming.
Later on in this and other courses you will learn other methods, but for now
this is probably the easiest.
The Keyboard class is compiled as part of a java package and must be identified
as such in your program with the line:
import cs1.Keyboard;
The javac compiler and the java runtime interpreter must be able to find the
Keyboard.class file in the cs1 package.
There are several ways to accomplish this, and it is not easy to say which is
preferable but here are some ideas.
1. Include the directory cs1 and the file it contains (Keyboard.class) in your
source directory.
2. Create a directory (for example: c:\myclasses) and copy the cs1 directory
here.
Then use the classpath variable to locate this and any other classes/packages
you might create.
Depending on your OS, you might add the followin line to autoexec.bat:
set CLASSPATH=.;c:\myclasses
or change the command line specification in Textpad.
3. For bluej, either use solution 1) (but you have to find the project
directory) or on the Tools\Preferences\Libraries tab you can add a path to
cs1.jar.
Note: cs1.jar is an alternative method of distributing packages, and bluej seems
to need this.
All things considered, solution 1 is probably the easiest for class work, since
you can carry the files easily from machine to machine on a floppy.