cbutton
asked on
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></HEA D>
<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.
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></HEA
<BODY>
<applet code="WelcomeApplet.class"
</BODY>
</html>
Both files are in the same directory. I'm using jdk1.2.1.
You are using Java 2.
You will have to learn about the
Java Plug-in and the HTML converter.
See the sun site.
You will have to learn about the
Java Plug-in and the HTML converter.
See the sun site.
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
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
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.
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.
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
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"
</applet>
</form>
</body>
</html>
place your html in the same directory.
All the best
Cheers,
Muru
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->ControlPa nel->...Pl ugIn. 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.
The second option is to dovnload Netscape 6.0, which suports by default Java2 platform and test your applets there.
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.
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.
ASKER
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?
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?
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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).
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!
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!
I just noticed that you are using JDK1.2.1.
My comments are from a JDK1.3 perspective
I think you shoud move up.
My comments are from a JDK1.3 perspective
I think you shoud move up.
ASKER
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.AccessContro lException : access denied (java.lang.RuntimePermissi on modifyThreadGroup)
at java.security.AccessContro lContext.c heckPermis sion(Unkno wn Source)
at java.security.AccessContro ller.check Permission (Unknown Source)
at java.lang.SecurityManager. checkPermi ssion(Unkn own Source)
at sun.applet.AppletSecurity. checkAcces s(Unknown Source)
at java.lang.ThreadGroup.chec kAccess(Un known Source)
at java.lang.Thread.init(Unkn own Source)
at java.lang.Thread.<init>(Un known Source)
at javax.swing.TimerQueue.sta rt(Unknown Source)
at javax.swing.TimerQueue.<in it>(Unknow n Source)
at javax.swing.TimerQueue.sha redInstanc e(Unknown Source)
at javax.swing.JApplet.<init> (Unknown Source)
at WelcomeApplet.<init>(Welco meApplet.j ava:6)
at java.lang.Class.newInstanc e0(Native Method)
at java.lang.Class.newInstanc e(Unknown Source)
at sun.applet.AppletPanel.cre ateApplet( Unknown Source)
at sun.plugin.AppletViewer.cr eateApplet (Unknown Source)
at sun.applet.AppletPanel.run Loader(Unk nown Source)
at sun.applet.AppletPanel.run (Unknown Source)
at java.lang.Thread.run(Unkno wn Source)
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.AccessContro
at java.security.AccessContro
at java.security.AccessContro
at java.lang.SecurityManager.
at sun.applet.AppletSecurity.
at java.lang.ThreadGroup.chec
at java.lang.Thread.init(Unkn
at java.lang.Thread.<init>(Un
at javax.swing.TimerQueue.sta
at javax.swing.TimerQueue.<in
at javax.swing.TimerQueue.sha
at javax.swing.JApplet.<init>
at WelcomeApplet.<init>(Welco
at java.lang.Class.newInstanc
at java.lang.Class.newInstanc
at sun.applet.AppletPanel.cre
at sun.plugin.AppletViewer.cr
at sun.applet.AppletPanel.run
at sun.applet.AppletPanel.run
at java.lang.Thread.run(Unkno
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.
After that I think you will be in business.
What kind of operations are done by your applet ? Read/Write or is a normal "HelloWorld applet" ?
ASKER
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);
}
}
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);
}
}
ASKER
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.
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.
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
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
ASKER
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.
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....