How to make, use and compile packages.
Example: the Pumpkin package, containing
two public classes Pumpkin and CarvedPumpkin. It is used in the applet myApplet, which
also needs the public class MouseHandler.
To start with, assume that all the files are in a current directory, referred to from now on as "current".
- Under Linux
- In the files containing the classes that you want to go into the package, add, as first line of
- Create a directory Pumpkin in the current directory:
Move the two files Pumpkin.java and CarvedPumpkin.java into this directory.
- Compile the package from outside the Pumpkin directory, i.e. from the current directory, as follows:
- Now let's take care of the rest of the program, where the package is being used. In the main program
myApplet.java, add the line:
- Compile the file from the current directory:
This will compile myApplet.java and MouseHandler.java
- Now you can view the applet as usually, by opening the myApplet.html file where it is invoked.
- Under Windows.
This seems to be trickier, so ask me if you want to do it on your own.
Read from Rebecca Hasti's notes,