aspose file tools*
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
Author

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

Peter Knight
Greenhorn

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.
====================================================
HTML CODE:
[CODE]
<HTML>
<HEAD>
<TITLE>A Simple Program</TITLE>
</HEAD>
<BODY>
Here is the output of my program:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"<br /> WIDTH = 150 HEIGHT = 150 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,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">
<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>
</NOEMBED></EMBED>
</OBJECT>
</BODY>
</HTML>
[CODE/]
=================================================
=================================================
Java Code
[CODE]
/*nn
* ColorSwitch.java
*
* 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() {
initComponents();
}
/** 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) {
exitForm(evt);
}
});

jLabel1.setOpaque(true);
getContentPane().add(jLabel1);

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) {
jButton1MouseClicked(evt);
}
});

getContentPane().add(jButton1);

jCheckBox1.setText("jCheckBox1");
getContentPane().add(jCheckBox1);

jTextField1.setText("jTextField1");
getContentPane().add(jTextField1);

pack();
}
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 = java.awt.Color.black;
else
currentColor = java.awt.Color.lightGray;
jLabel1.setBackground (currentColor);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @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;
}
[CODE/]
Cindy Glass
"The Hood"
Sheriff

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
 
Don't get me started about those stupid light bulbs.
 
subject: 2.Problem when running with browser,fine when run with "java colorswitch.ColorSwitch"
 
Similar Threads
Problem when running with browser, fine when run with "java colorswitch.ColorSwitch"
Problem With GUI of Net Beans
simple login - help asp
call another form/frame(?) show method
NOT Abstract ERROR