Cannot see applet in browser

Hi,

I have j2sdk1.4.2 in my computer and works fine compiling and running java program. But I can see the applet in browser. What I could see was only a grey rectangle. What is wrong and how could i rectify.

Thanks
ricjavaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
open it via the java icon in your system tray.
if its not there, your browser may not be using the plugin as your default vm (which could be the cause of your problems). You can set the default VM thru IE's advanced options, or via the plugin control panel.
0
 
objectsCommented:
check the java console for errors.
0
 
NetworkArchitekCommented:
Hi ricjava,
Did you update your JRE as well? Also, check to make sure you do not have any misspellings in your code. Your class name must match up correctly.


Cheers!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ricjavaAuthor Commented:
hi NetworkArchiteck - no misspellings :)

hi objects - how do i check the java console?
0
 
ricjavaAuthor Commented:
I have checked the option Java Console Enable in IE and restarted but still cannot see my applet working in browser - only grey rectangle.

Also how do I set system tray to have java icon?
0
 
objectsCommented:
if its not there, it probably means that the plugin isn't running.
check that the plugin is set as the default vm for your browser.
0
 
ricjavaAuthor Commented:
do i have to install JRE as well?

Ok, now I go to IE view, Java Console.

I saw the error of

Error loading class: HelloWorld
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: HelloWorld
      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

0
 
objectsCommented:
does your applet use java2 features?
If so then you'll need to use the plugin to run it instead of the MS VM.
0
 
ricjavaAuthor Commented:
It is just a simple two files

<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>

Here is the output of my program:
<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>

that is my html file and  the HelloWorld.class is in the same folder
0
 
ricjavaAuthor Commented:
This is my applet code

import java.applet.Applet;
import java.awt.Graphics;

public class HelloWorld extends Applet {
    public void paint(Graphics g) {
        g.drawString("Hello world!", 50, 25);
    }
}


0
 
OviCommented:
Seems to me that your applet class is not correctly seen by the browser. Please checck the <applet> tag for path consistency to your classpath.

For example, if your HelloWorld class file is located in the same directory as the html page which is suposed to launch the applet, the tag should look like:

<applet codebase="." class="HelloWorld.class" code="HelloWorld" width="100" height="100">
... applet parameters if any .....
</applet>

If your class file is located in a directory called for example 'classes', located on the same level as the html page, the tag must be updated accordingly, like this:

<applet codebase="./classes/" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
... applet parameters if any .....
</applet>


This should solve your problem.
0
 
ricjavaAuthor Commented:
I have installed j2sdk1.4.2 in my computer months ago and running fine with java application.

Doesn't installing j2sdk1.4.2  make the plug-in available?
0
 
OviCommented:
Seems to me that your applet class is not correctly seen by the browser. Please checck the <applet> tag for path consistency to your classpath.

For example, if your HelloWorld class file is located in the same directory as the html page which is suposed to launch the applet, the tag should look like:

<applet codebase="." class="HelloWorld.class" code="HelloWorld" width="100" height="100">
... applet parameters if any .....
</applet>

If your class file is located in a directory called for example 'classes', located on the same level as the html page, the tag must be updated accordingly, like this:

<applet codebase="./classes/" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
... applet parameters if any .....
</applet>


This should solve your problem.
0
 
ricjavaAuthor Commented:
Ovi - i tried your recommendation but didn't work
0
 
OviCommented:
Tell me how are the files stored on your computer?
0
 
OviCommented:
... is by any chance your class stored in a .jar file? If yes, the applet tag must look like this:
<applet codebase="." archive="your_jar_file.jar" class="HelloWorld.class" code="HelloWorld" width="100" height="100">
... applet parameters if any .....
</applet>
0
 
OviCommented:
Error loading class: HelloWorld
java.lang.NoClassDefFoundError
java.lang.ClassNotFoundException: HelloWorld

The only reason you get this exception is because the virtual machine cannot find your class, to load'it and launch. There is no other cause than incorrect classpath setup.
0
 
ricjavaAuthor Commented:
i have two files: helloworld.html and HelloWorld.class, both in c:\myprogram folder.

Content of helloworld.html

<HTML>
<HEAD>
<TITLE> A Simple Program </TITLE>
</HEAD>
<BODY>

Here is the output of my program:
<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25>
</APPLET>
</BODY>
</HTML>

content of HelloWorld.java

import java.applet.Applet;
import java.awt.Graphics;

public class HelloWorld extends Applet {
    public void paint(Graphics g) {
        g.drawString("Hello world!", 50, 25);
    }
}


Problem: When I open the browser with url of C:\myprogram\helloworld.html
I got grey rectangle.

Also on this page http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html
I also saw a grey rectangle

0
 
objectsCommented:
compile your applet with "-target 1.1"

eg.

javac -target 1.1 HelloWorld.java
0
 
ricjavaAuthor Commented:
i got a warning

Warning: classic VM not supported;client VM will be used
0
 
objectsCommented:
> There is no other cause than incorrect classpath setup.

not true, it can be caused by many things.
in fact the classpath should have little affect on an applet.
0
 
OviCommented:
Please update the applet tag with all valid parameters, setup as previously described in my message.
0
 
OviCommented:
>>not true, it can be caused by many things.

Like what? Please be so kind and share your knowledge with me on this too :). Thank you.
0
 
objectsCommented:
> i got a warning
> Warning: classic VM not supported;client VM will be used

running what command exactly?
0
 
ricjavaAuthor Commented:
hi objects - I can see the applet working now after i compiled with
javac -target 1.1 HelloWorld.java

By the way, does it mean that my browser is using 1.1 vm?
0
 
objectsCommented:
> does it mean that my browser is using 1.1 vm?

that is correct, the MS VM only supports 1.1.
0
 
ricjavaAuthor Commented:
I don't want to use Ms VM, what should I do?

I already have jsdk1.4.2 installed in my computer
0
 
objectsCommented:
you need to set IE to use the plugin as the default VM.
This can be done from the advanced options, or the plugin control panel.
0
 
objectsCommented:
thats assuming that the plugin is installed :)
(it should be by default)
0
 
ricjavaAuthor Commented:
i can see java plugin under the Add or Remove program

I can see Java 2 SDK, SE v1.4.2 only.

I plan to remove it and download the sdk from sun website again to install.
0
 
ricjavaAuthor Commented:
can't see java plugin under the Add or Remove program
0
 
ricjavaAuthor Commented:
or is it necessary to do that?
0
 
objectsCommented:
you should have "Java2 Runtime Environment"
If you don't then you'll need to install it.
0
 
OviCommented:
The plugin is not visible. Instead you see the JDK and the JRE. They are installed automatically. The plugin also is installed automatically into your system, as part of the JRE.

You just need to go in Internet Explorer->Tools->InternetOptions->Advanced tab->Select the "Use JRE 1.4 for <applet> (requires restart)".
0
 
OviCommented:
The plugin should be visible under Control Panel -> Java entry. That is the Java Plug-in Control Center, from which you should be able to enable the plug-in for your browser.
0
 
ricjavaAuthor Commented:
You mean I should see the Java entry in Start ->Settings->Control Panel?
0
 
OviCommented:
yes, there should e an entry called Java. That's one way of setting the plugin. I recomend you to do'it from  your browser too.
0
 
objectsCommented:
> The plugin should be visible under Control Panel -> Java entry

mention that earlier.
But if you don't have Java Runtime Environment" in your Add/Remove programs then you won't have the control panel.
0
 
ricjavaAuthor Commented:
yes, I dont' have the Java Runtime Environment in my Add/Remove program..and therefore no Java entry in Control Panel....


So i need to  download the jre to install it. The jre version doesn't have to be the same version as my j2sdk1.4.2, isn't it?
0
 
objectsCommented:
no it doesn't.
1.4.1_06 is the latest I think
0
 
objectsCommented:
i mean 1.4.2_06
:)
0
 
OviCommented:
Normaly when you have installed the J2SDK, the JRE get's automatically installed too. In any case, go to Sun site and download the JRE. I suggest to use the same version for compatbility issues, even if I did not find any problem like this in my previous experience (you can have multiple JVM installations on the same computer).
0
 
OviCommented:
1.5.0 is the latest, from Tiger release.
0
 
ricjavaAuthor Commented:
i can now see the applets working already after i installed jre. Initially, I thought I have plug-in as I already installed j2sdk1.4.2.  Actually, I didn't have it.

Thanks for everyone's help.

0
All Courses

From novice to tech pro — start learning today.