In not sure if it's creating packages or using them that you don't understand, so I'll walk you through an example.
1. Create a new folder called "test"
2. Create in that folder a file called "Test.html":
Code:
<html>
<body>
<applet height="50", width="300" code="MainAppletFile.class">
</applet>
</body>
</html>
3. Create in that folder a file called "MainAppletFile.java":
Code:
import java.applet.Applet;
import java.awt.Graphics;
import net.trycatch.applet.FileInPackage;
public class MainAppletFile extends Applet {
public void paint(Graphics g) {
FileInPackage fip = new FileInPackage("Hello World from inside a package!");
g.drawString(fip.getMessage(), 50, 25);
}
}
As you can see, we're using a class called "FileInPackage". We haven't created that yet...but here it comes....
4. Create a new folder in "test" called "net".
5. Create a new folder in "net" called "trycatch".
6. Create a new folder in "trycatch" called "applet"
7. Create a new file in "applet" called "FileInPackage.java":
Code:
package net.trycatch.applet;
public class FileInPackage {
private String msg;
public FileInPackage(String msg) {
this.msg = msg;
}
public String getMessage() {
return this.msg;
}
}
8. Compile "FileInPackage.java".
9. Move back to the "test" folder and compile "MainAppletFile.java".
10. Open "Test.html" in your browser. You should see "Hello World from inside a package!".
OK. There are the steps, now a little word about what we've done.
We created an HTML file and referred to a file called "MainAppletFile.class" which is our main applet file. This file refers to a class called "net.trycatch.applet.FileInPackage". We therefore created a package hierarchy for the class (as you do when creating a package) and the class itself.
Hope this helps.
Bookmarks