File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes 2.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
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

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

Peter Knight

Joined: Sep 23, 2001
Posts: 5
Sorry for the double post... but whenever I reply to the other message, it increments the reply counter and no reply shows up.
Anyway hope this works.
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 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 his time... If not, I noticed you can see
the code if you edit the message.
<TITLE>A Simple Program</TITLE>
Here is the output of my program:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"<br /> WIDTH = 150 HEIGHT = 150 codebase=",3,0,0">
<PARAM NAME = CODE VALUE = "colorswitch.ColorSwitch" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<EMBED type="application/x-java-applet;version=1.3" CODE = "colorswitch.ColorSwitch" WIDTH = 150 HEIGHT = 150 scriptable=false pluginspage=""><NOEMBED></COMMENT>
Java Code
* Created on September 18, 2001, 9:23 PM
package colorswitch;
* @author Peter
public class ColorSwitch extends javax.swing.JFrame {
/** Creates new form ColorSwitch */
public ColorSwitch() {
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jTextField1 = new javax.swing.JTextField();

getContentPane().setLayout(new java.awt.GridLayout(4, 2));

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {


jButton1.setFont(new java.awt.Font("Dialog", 1, 14));
jButton1.setText("Color Switch");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {




private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
if (currentColor == java.awt.Color.lightGray)
currentColor = java.awt.Color.gray;
else if (currentColor == java.awt.Color.gray)
currentColor =;
currentColor = java.awt.Color.lightGray;
jLabel1.setBackground (currentColor);
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
* @param args the command line arguments
public static void main(String args[]) {
new ColorSwitch().show();

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JButton jButton1;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
private java.awt.Color currentColor = java.awt.Color.lightGray;
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
I edited your other post to fix the formatting - so I am closing this one.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: 2.Problem when running with browser,fine when run with "java colorswitch.ColorSwitch"
It's not a secret anymore!