This document should get you up to speed compiling and running your java programs for the Person machine Communications course.
Java code is compiled into a platform independant form called 'bytecodes'. These bytecodes are stored in .class files, which are created, one for each of your objects, byt the java compiler. These class files are then read in and executed by the java program. Read more about java on Sun's Java site.
The original Java had objects for making buttons and user interfaces, and the collection of these objects was called the AWT (Abstract Windowing Toolkit). Since then, these objects have been revised and a new collection (or package, as they are called in javaese) called Swing has been created by Sun.
Compiling your code is a matter of letting the javac compiler program know where it can find all the pieces (.class files) that are used by your program. There are two steps:
You can use the following script we have written to automatically set up your classpath and compile your code. Download the script from here, save it into the directory containing your source files, and run it as follows:
% swingjavac [options] myjavafile1.java myjavafile2.java
Where options are optional flags to the javac compiler.
To run the code, you have to use the java program, and tell
it where all the classes to run are, not only the default and
Swing classes, but also the .class files for your code
that you just compiled. Basically, this just involves setting
up your classpath correctly. The right classpath is:
Again, we've made a handy script for you, which you can download here, and put in the same directory as your .class files to run them. Run as follows:
% swingjava [options] myclassname
Where options are flags to the java program, and myclassname is just that, the name of the class file containing your main() function.
Compare the following (approximately worded) error messages with the problems you are having: