Click to See Complete Forum and Search --> : need help to start using applet


SallyZhao
06-14-2006, 11:41 AM
Hi,

I am new to java applet and got stuck in using it. I am starting with the clock example provied on web. I download the source code and compiled in JDK1.5.0_06 and try to display the applet in IE browser. As I did the web page using NetBean5.5 web application template, the applet class appeared in the classes folder under WEB_INF. The following is the web page script:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>

<applet codebase="classes" code="Clock.class" height="200" width="200"></applet>

</body>
</html>

When I run the web page, the browser just display a grey blank box and the Java console tells me this error message:

Microsoft (R) VM for Java, 5.0 Release 5.0.0.3810
==============================================
? help
c clear
f run finalizers
g garbage collect
m memory usage
q quit
t thread list
==============================================
java.lang.ClassNotFoundException: Clock
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.securedClassLoad
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run

I have no idea about this. Can anybody help please? Thanks in advance.

Khalid Ali
06-14-2006, 02:20 PM
This clearly means that browser does not know where the Clock.class file is...
Make sure the html page is in the same location where class file is.

SallyZhao
06-15-2006, 03:54 AM
Actually, I didn't put class file in the same folder of the html file. It is in the subfolder named classes, so I put codebase="classes" in the applet tag.
Do I have to always put them in the same folder?

Khalid Ali
06-15-2006, 08:45 AM
no..but you will have to make sure that the place where you have put ur file is visible to the web page

mwmwnmw
06-15-2006, 03:57 PM
If I may... and I'm probably wrong but.....

<applet codebase="classes" code="Clock.class" height="200"

I don't believe that this really tells the JVM anything at all about the location of Clock.class. As I understand it, and again, I'm probably wrong, but codebase needs either an actual URL or a relative path. What you are saying here is that the file "Clock.class" is located in the file "classes", which is impossible. It would have to be either....

codebase="http://www.yoursite.com/classes/"

or

codebase="/classes/"

assuming, of course, that classes is directory inside your root html directory. If not you would need to supply the JVM with the proper navigation.

Khalid Ali
06-15-2006, 05:13 PM
just to make this work for you....
put ur html page that has applet code in it, in the classes folder,
put ur applet class file in the same folder
classes/
*.html
*.class
now in the applet code in the html page change codebase to this
codebase="."
and then test ur applet...this will give u what this all about that visibility of class and stuff..:-)

SallyZhao
06-16-2006, 03:35 AM
I put them in the same folder. It still doesn't work. So I tried to run my applet in Netscape browser and it works fine. It seems something wrong with my IE browser. What can that be? I can run some online applet examples using IE browser but not with my applet.

Khalid Ali
06-16-2006, 09:05 AM
:mad:
First thing u always want to do is make sure that you have the JRE correctly installed from ur browsers...(download it from java site and re-install it)

SallyZhao
06-16-2006, 11:15 AM
Thanks, Khalid. I re-install the JRE for IE browser and now it works. Thanks a lot for your help.

Sally