Java applet won't display in firefox
Hi, I am trying to get a java applet to display in firefox and it won't run. The code is from my Java book cd. I get the following error from the browser. Any help GREATLY appreciated. Thanks. Derek:D
__________________________________________________ __________
Java Plug-in 1.6.0_25
Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\derek
----------------------------------------------------
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
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.lang.reflect.InvocationTargetException
at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Un known Source)
at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: PushCounter cannot be cast to java.applet.Applet
at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.reflect.InvocationTargetException
__________________________________________________ ____________
Here are the contents of my html file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
</style>
</head>
<body>
<applet code="PushCounter.class" width="100" height="100"</applet>
</body>
</html>
Here are the contents of my two .java files.
Code:
//********************************************************************
// PushCounter.java Authors: Lewis/Loftus
//
// Demonstrates a graphical user interface and an event listener.
//********************************************************************
import javax.swing.JFrame;
public class PushCounter
{
//-----------------------------------------------------------------
// Creates the main program frame.
//-----------------------------------------------------------------
public static void main (String[] args)
{
JFrame frame = new JFrame ("Push Counter");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new PushCounterPanel());
frame.pack();
frame.setVisible(true);
}
}
and here
Code:
//********************************************************************
// PushCounterPanel.java Authors: Lewis/Loftus
//
// Demonstrates a graphical user interface and an event listener.
//********************************************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PushCounterPanel extends JPanel
{
private int count;
private JButton push;
private JLabel label;
//-----------------------------------------------------------------
// Constructor: Sets up the GUI.
//-----------------------------------------------------------------
public PushCounterPanel ()
{
count = 0;
push = new JButton ("Push Me!");
push.addActionListener (new ButtonListener());
label = new JLabel ("Pushes: " + count);
add (push);
add (label);
setPreferredSize (new Dimension(300, 40));
setBackground (Color.cyan);
}
//*****************************************************************
// Represents a listener for button push (action) events.
//*****************************************************************
private class ButtonListener implements ActionListener
{
//--------------------------------------------------------------
// Updates the counter and label when the button is pushed.
//--------------------------------------------------------------
public void actionPerformed (ActionEvent event)
{
count++;
label.setText("Pushes: " + count);
}
}
}
I have also posted this question here Java applet won't display in firefox (Beginning Java forum at JavaRanch)