aspose file tools*
The moose likes Beginning Java and the fly likes Problem when running with browser, fine when run with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"" Watch "Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"" New topic
Author

Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"

Peter Knight
Greenhorn

Joined: Sep 23, 2001
Posts: 5
Hello, I am new to java are have a problem with a swing app. When I run "java colorswitch.ColorSwitch" it works, but when I use the below html snipper it gives this error....
java.lang.ClassCastException: colorswitch.ColorSwitch
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source).....

I am using Forte and it also runs fine if I run the .class file direcly in Forte.
Any help would be greatly appreicated.
====================================================
HTML CODE
........
<PARAM NAME = CODE VALUE = "colorswitch.ColorSwitch" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" CODE = "colorswitch.ColorSwitch" WIDTH = 150 HEIGHT = 150 scriptable=false......<br /> ......
=====================================================
Peter Knight
Greenhorn

Joined: Sep 23, 2001
Posts: 5
Hmmm the HTML code didn't show up... I guess cause HTML is on (don't know how to turn it off but maybe this will work)....
==============================
HTML CODE..
.PARAM NAME = CODE VALUE = "colorswitch.ColorSwitch" >
.PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
.PARAM NAME="scriptable" VALUE="false">
.COMMENT>
.EMBED type="application/x-java-applet;version=1.3" CODE = "colorswitch.ColorSwitch" WIDTH = 150 HEIGHT = 150 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT>
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
Could you possibly provide a little more info? Does your ColorSwitch class extend Applet? This could cause a problem.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
To be clearer what I meant was that if your ColorSwitch class should extend Applet, if it does not may be a problem. I didn't see any of your HTML what does the < APPLET> tag look like.
[This message has been edited by Cindy Glass (edited September 25, 2001).]
Peter Knight
Greenhorn

Joined: Sep 23, 2001
Posts: 5
Hopefully better explained this time.....
I am new to java are have a problem with a Swing app. When I run "java colorswitch.ColorSwitch" it works, but when I run it from a browser (with the below html code) it gives this error....
java.lang.ClassCastException: colorswitch.ColorSwitch
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source).....
I am using Forte and it also runs fine if I run the .class file directly in Forte. I have also included the Java code (but I think the java is just fine as it works when I run it directly)
Any help would be greatly appreicated. Thanks in advance....
PS: To get the HTML code I used the Java "Converter"
PPS: Hopefully the code comes out this time... If not, I noticed you can see the code if you edit the message.
====================================================
HTML CODE:

=================================================
=================================================
Java Code


[This message has been edited by Cindy Glass (edited September 25, 2001).]
James Gray
Ranch Hand

Joined: Sep 10, 2001
Posts: 30
Your class runs fine as a stand alone program because it is a stand alone program and it doesn't run fine as an applet, because it is not and applet. Giving it a main() method give the VM something to start up when it's run as a program. Applets follow different rules. First, at least one of the classes involved must extend Applet or JApplet (the swing version and more relavent in this case). Main() is never called for applets though. They have different methods you can override based on their life-cycle: init(), start(), paint() - used more with Applet than JApplet, stop(), and destroy(). Programs are often written to function as both application and applet, but you'll have to provide both sets of requirements. I recommend bouncing over to Sun's Java Tutorial and reading up on applets, then see if you can modify your code to work under both paradimes. It's not too tough. Good luck!
Peter Knight
Greenhorn

Joined: Sep 23, 2001
Posts: 5
Okay..... great, thanks for your help. I will check out the differences between a applet and an application.
Thanks again.
 
 
subject: Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"