?
Solved

Runs in appletviewer but not in browser

Posted on 2001-06-05
21
Medium Priority
?
450 Views
Last Modified: 2013-11-23
Although I have been a programmer for many years, I am just now trying to learn Java. I don't seem to be able to get any applets (that I write) to run in either Netscape or IE. They seem to run fine in appletviewer, but in my browsers I get a message saying the class cn't be found. Even a simple "Hello World!" applet won't run. The demo applets that came with the JDK run fine in both browsers, so I know they can run applets.
Here's my applet code:

//First Java applet
import javax.swing.JApplet;
import java.awt.Graphics;
public class WelcomeApplet extends JApplet {
   public void paint(Graphics g)
   {
      g.drawString("Welcome to my first applet", 25, 25);
   }
}

And here's my HTML:

<HTML>
<HEAD><TITLE></TITLE></HEAD>
<BODY>
<applet code="WelcomeApplet.class" width=300 height=30></applet>
</BODY>
</html>

Both files are in the same directory. I'm using jdk1.2.1.
0
Comment
Question by:cbutton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +4
21 Comments
 
LVL 3

Expert Comment

by:Sendoh
ID: 6158252
hi !
i think for this case is ur classpath that cause problem.... else maybe u could check ur html files are they placed together with the classpath ?

hope it helps....
0
 
LVL 28

Expert Comment

by:rrz
ID: 6158371
You are using Java 2.
You will have to learn about the
 Java Plug-in  and the HTML converter.
 See the sun site.
0
 

Expert Comment

by:sobhan_genie
ID: 6158461
Hello,

           You can try the following things...

1)Remove classpath from system variables i.e., from properties of "MyComputer" this gives a lot of problems.

2)You can give CODEBASE=. and archive=swing.jar or rt.jar(with relative path to codebase)

3)You should have a plugin installed for your browser and always run "HTML converter" on ur html file which will do all necessary things.
http://java.sun.com/products/plugin/1.3/docs/html_converter.html
http://java.sun.com/products/plugin/1.1.2/plugin-install.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6158482
Hi CButton

Please change ur JApplet to Applet then your code will run perfectly.

If u want to use JApplet then u need to load Java-Plugin or from www.javasoft.com.
Please load the Plugin

And instead of Applet tag use Object Tag for Explorer and Embed Tag for Netscape

Not interested in Plugin then u need to archive rt.jar or swingall.jar available in www.javasoft.com
U can see the result.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 6158883
Hai cbutton,

    Make use of the codebase.  You have to add the form tag in your html to view this in the netscape browser.

<html>
  <head>
    <title>
       first applet
    </title>
  </head>
  <body>
    <form name="frm">
        <applet code="WelcomeApplet.class"       codebase=<directory> width=300 height=30>
       </applet>
    </form>
  </body>
</html>

place your html in the same directory.

All the best


Cheers,
Muru
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6159384
Usage of Java2 platform for applets (JApplet's) require the usage of the javaPlug-in which comes with the JRE and JDK. In order to use this, you must start the plug-in from Start->Settings->ControlPanel->...PlugIn. After that you must convert your html file which loads the JApplet with the required version of the HTMLConverter, Downloadable from Sun. And that's all.

The second option is to dovnload Netscape 6.0, which suports by default Java2 platform and test your applets there.
0
 
LVL 28

Expert Comment

by:rrz
ID: 6159901
You don't have to start the plug-in from the control panel.
 MSIE uses the "Object tag" (which you can use the HTML converter to produce the tag or you can type it in yourself) will be recognized by the browser and will call the plug-in.
In the tag there is a long number called  CLSID  this you will  find in your system registry (see HKEY_CLASSES_ROOT , Javasoft.JavabeansBridge).
The Plug-in will install the JRE in a directory called JavaSoft within your Program Files directory.
The whole thing works fine, but is slow.
 
0
 

Author Comment

by:cbutton
ID: 6162296
I was unable to use Ovi's proposed solution. Plugin doesn't show up in my control panel.

I am leaning toward sobhan_genie's advice, but I'm missing something. I downloaded the plugin, as suggested, and installed it. I also downloaded the HTMLConverter, installed it and converted my HTML file. But when I bring it up in my browser, it wants to download the plugin again. I reinstalled plugin. Same problem. Whatsupwiththat?
0
 
LVL 28

Expert Comment

by:rrz
ID: 6162353
You should have the duke icon in your control panel,  
if you successfully installed the plug-in. This is where you access the "java Plug-in Properties" dialog box. I have two dukes in my Control Panel. One for IE and one for Netscape 6 . It took a while to configure but I did get one working for both. See my last comment again.
0
 
LVL 9

Accepted Solution

by:
Ovi earned 400 total points
ID: 6162483
THE PLUGIN MUST BE ENABLED IN YOUR BROWSER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ... FROM THE CONTROL PANEL. SO DOWNLOAD THE JRE AND TAKE A LOOK THERE AND YOU WILL FIND'IT.
0
 

Author Comment

by:cbutton
ID: 6165586
Okay. Now I find the Plugin icon in my control panel. I think I configured it okay. Must I be online in order to test my applet? I see that the converted HTML file has a link to the Sun web site. And when  try to run it, it tries to dial up.

I'll play around with it again tonight and see if I can get it to work. I don't have time until then.

Thank y'all for being patient.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6166668
It tries to dial up only if your plug-in is still not enabled . Try to use Netscape4.x as a browser, and in the "Help->About Plug-ins" option you will find an html file with all the browser plugins and their states (enabled or not).
0
 
LVL 28

Expert Comment

by:rrz
ID: 6168389
No, you don't have to be on line. The plug does not dial up. The browser sees the Object tag. Gets the CLSID( see my above comments) and looks it up in your system registry.
Using the JavaSoft.JavabeansBridge your system finds the JavaSoft directory in your Program Files(I am assuming Win98).Finally the JRE finds a JVM .  Look for the files!
0
 
LVL 28

Expert Comment

by:rrz
ID: 6168411
I just noticed that you are using JDK1.2.1.
My comments are from a JDK1.3 perspective
I think you shoud move up.
0
 

Author Comment

by:cbutton
ID: 6172535
I downloaded JRE again and installed it. Then I configured the plugin in my control panel. Now it works fine with IE, but it doesn't work in Netscape 4.7. Here's what the Java console says:

Java(TM) Plug-in: Version 1.3.1
Using JRE version 1.3.1 Java HotSpot(TM) Client VM
User home directory = C:\WINDOWS
Proxy Configuration: no proxy

----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
q:   hide console
s:   dump system properties
t:   dump thread list
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
     at java.security.AccessControlContext.checkPermission(Unknown Source)
     at java.security.AccessController.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkPermission(Unknown Source)
     at sun.applet.AppletSecurity.checkAccess(Unknown Source)
     at java.lang.ThreadGroup.checkAccess(Unknown Source)
     at java.lang.Thread.init(Unknown Source)
     at java.lang.Thread.<init>(Unknown Source)
     at javax.swing.TimerQueue.start(Unknown Source)
     at javax.swing.TimerQueue.<init>(Unknown Source)
     at javax.swing.TimerQueue.sharedInstance(Unknown Source)
     at javax.swing.JApplet.<init>(Unknown Source)
     at WelcomeApplet.<init>(WelcomeApplet.java:6)
     at java.lang.Class.newInstance0(Native Method)
     at java.lang.Class.newInstance(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
0
 
LVL 28

Expert Comment

by:rrz
ID: 6172667
I got this same exception . The JVM is throwing an exception because it sees your class file on your local machine(not on the server where it suppose to be). My solution was to pack all class files and image files into jar files.Tell the  Object tag to look for archive.
After that I think you will be in business.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6176877
What kind of operations are done by your applet ? Read/Write or is a normal "HelloWorld applet" ?
0
 

Author Comment

by:cbutton
ID: 6178369
Ovi,
It's just a simple applet.

//First Java applet
import javax.swing.JApplet;
import java.awt.Graphics;
public class WelcomeApplet extends JApplet {
  public void paint(Graphics g)
  {
     g.drawString("Welcome to my first applet", 25, 25);
  }
}
0
 

Author Comment

by:cbutton
ID: 6188571
rrz:
Man! I'm so new at Java that I don't even know what you're taling about when you mention "jar" files. I assume I'll eventually learn about them, but I haven't yet.

Sorry to take so long getting back here, but I've been busy with other things.
0
 
LVL 28

Expert Comment

by:rrz
ID: 6196778
Go to  sun site for good tutorials.
You are using the javac tool to compile.
Use the jar tool to pack your files into jar files.
To learn about jar just type jar and press  enter.
I type the following.
     jar cvf Myjar.jar One.class Two.class
0
 

Author Comment

by:cbutton
ID: 6200573
It was difficult deciding who should get the points, but Ovi's answer (which I rejected) and his or her comments led me to redownload the JRE, and then things started working, so I am awarding the points based on that.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question