[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

Runs in appletviewer but not in browser

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
cbutton
Asked:
cbutton
  • 7
  • 6
  • 4
  • +4
1 Solution
 
SendohCommented:
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
 
rrzCommented:
You are using Java 2.
You will have to learn about the
 Java Plug-in  and the HTML converter.
 See the sun site.
0
 
sobhan_genieCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
shyamkumarreddyCommented:
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
 
mmuruganandamCommented:
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
 
OviCommented:
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
 
rrzCommented:
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
 
cbuttonAuthor Commented:
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
 
rrzCommented:
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
 
OviCommented:
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
 
cbuttonAuthor Commented:
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
 
OviCommented:
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
 
rrzCommented:
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
 
rrzCommented:
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
 
cbuttonAuthor Commented:
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
 
rrzCommented:
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
 
OviCommented:
What kind of operations are done by your applet ? Read/Write or is a normal "HelloWorld applet" ?
0
 
cbuttonAuthor Commented:
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
 
cbuttonAuthor Commented:
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
 
rrzCommented:
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
 
cbuttonAuthor Commented:
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

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!

  • 7
  • 6
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now