GeeCON Prague 2014*
The moose likes Applets and the fly likes Running an applet in a web browser. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Applets
Bookmark "Running an applet in a web browser." Watch "Running an applet in a web browser." New topic
Author

Running an applet in a web browser.

Houssam Haitof
Greenhorn

Joined: Oct 04, 2001
Posts: 11
Hello,
I made a simple applet and a simple html file to run this applet in a browser. But when I load the html file into a web browser it told me that MyApplet could not be found. I tried "appletviewer MyFile.html" in the shell and it worked. Does any body have an idea about this problem? My CLASSPATH contains only "."
Thank you in advance.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Houssam,
Make sure that you have your HTML and jar/class files in the same directory. Load it into your browser using open as a file.
Regards,
Manfred.
Houssam Haitof
Greenhorn

Joined: Oct 04, 2001
Posts: 11
Thank you for your interest, yes the html file and the class file are in the same directory. I load my file using File/Open or just by double clicking on it and it still does not work :/
peter johansson
Greenhorn

Joined: Oct 25, 2001
Posts: 9
Make sure you refer to the right class. Thus, if the applet lies in a package called "mypackage" and the applet classfile is called MyApplet.class a legal name for the class would be "mypackage.MyApplet.class".
E.g.
This is the applet-tag(note: the classloader looks for the classes, begining from the html-document)
<Applet code="mypackage.MyApplet.class" width="300" height="300"></Applet>
Another example:
If you put your classes in a jar-file you could use the "archive" attribute like this.
<Applet code="mypackage.MyApplet.class" archive="myarchive.jar" width="300" height="300"></Applet>
Note:When you put your classes in a jar the browser only opens one connection and loads all the classes at the same time. Otherwhise the browser opens a new connection for each file it download.
regards,
/Peter

Originally posted by Houssam Haitof:
Thank you for your interest, yes the html file and the class file are in the same directory. I load my file using File/Open or just by double clicking on it and it still does not work :/

 
GeeCON Prague 2014
 
subject: Running an applet in a web browser.