Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running an applet in a web browser.

 
Houssam Haitof
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :/

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic