TrainBeaser for iPhone
The moose likes Applets and the fly likes how to get applet work in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "how to get applet work in browser" Watch "how to get applet work in browser" New topic
Author

how to get applet work in browser

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Hi
I just created a fun game by using applet. It works fine in appletviewer, but when I try to view it in the browser, it shows nothing but a empty gray image.
In the browser's status bar, i saw XX.class not found when I mouse over on the image.
Thanks!
lee dalais
Ranch Hand

Joined: Feb 28, 2001
Posts: 67
what browser are u using, i've had problems with older browsers not finding the classes, newer browsers should wrk, eg: ie5
Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
Make sure your classpath is correctly set. it should be set to include the dir that the .class file is in.
Matt
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
I am using Explorer 5. But, I don't know how to set up the classpath. I installed JDS in C drive and save all my other java programs in D drive. Can you give me a guide of how to set up the classpath properly, please.

Thank you very much!
Mindy
Jan Volkmann
Greenhorn

Joined: Feb 01, 2001
Posts: 17
Originally posted by Mindy Wu:
[I]Can you give me a guide of how to set up the classpath properly, please.
I]

Keep the *.html file in the same directory as the applet's class file is in. Edit the html file and remove codebase from the applet-tag. Insert code="[I]AppletName[I].class" if necessary.
Do not use packages unless you like asking for troubles. Although Sun claims it to be possible
cf. http://web2.java.sun.com/docs/books/tutorial/applet/overview/test.html
I spent three days on it without success. When the applet is loaded the JVM apparently interprets the package-statement as part of the path and looks for the applet class in yet another subdirectory named after the package. I would do so until Kingdom Come, I suppose.
An IDE's appletviewer is much smarter in a way. It has the advantage of having more info about paths'n'packages so it let's you get away with lots of things. This is not beneficial, I think 'cos it is often misleading when trying to detect an error.
hope it helps,
Jan
Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
Are you trying to use IE to view an applet on your PC or on a server? If you are trying to view it on your PC, then put the applet in the same dir as your .html file and then if your
applet .class file is in d:\iamcool\whyislifesofunky then
to set your classpath type set CLASSPATH=d:\iamcool\whyislifesofunky;%CLASSPATH%
Try this. If this doesn't work let me know.
It is also possible that you don't have support for
Java turned on in your browser...you might check that.

With Respect,
Matt
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Thank you for your kindness. However, I still could not get it work. I do run my program at my local PC, and I did have Java enabled in my browser. I try to setup the classpath in dos as you instructed, for example: my class is in d:\My_Room\Java1.3\game.class. I included this directory in my html file, but it is still not working. Actually, after I installed the Standard Java Development Kit, I never setup any classpath in dos, and I still don't know how, can you give me more assistance. Thanks again.
Mindy
Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
Let's see, I'm all confused because I'm running a server at home
and I do applets on another server and then run them locally. So, I may have given bad advice. Can you show your .html file
and what you type in to the http:// field of your browser? It should be as simple as: if your .class file that you want to load is in c:\mattiscool, then set your classpath to that dir. Just to get you up and running, opne a dos window and type
set path=c:\jdk1.2.2\bin;%PATH%
set classpath=c:\mattiscool;%classpath%
then go to your browser and in the http field type
c:\mattiscool\coolApp.html
where coolApp.html looks something like
<html>
<applet code = coolmatt.class height = 400, width = 400>
</applet>
</html>
That SHOULD do it. Let me know if it doesn't.
Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
Hello, I'm throwing in a classpath/path link. It's pretty handy. You have to click about three pages into the tutorial to get to the stuff about classpath & path statements
<a href="http://www.naviseek.com/book/java2412/jdkhelp1.shtml"> http://www.naviseek.com/book/java2412/jdkhelp1.shtml
</a>
 
jQuery in Action, 2nd edition
 
subject: how to get applet work in browser
 
Threads others viewed
Can't run my applet on a html page
Why don't running the applet developping the JAI package&#65311;
transparent applet and motion image
Refresh problem in applet
Applets on Linux
developer file tools