Results 1 to 7 of 7
- 05-12-2011, 09:29 PM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
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:
Here are the contents of my two .java files.Java 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>
and hereJava 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); } }
I have also posted this question here Java applet won't display in firefox (Beginning Java forum at JavaRanch)Java 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); } } }Last edited by silverglade; 05-12-2011 at 10:06 PM.
- 05-12-2011, 10:31 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
means: PushCounter must extend java.applet.AppletJava Code:Caused by: java.lang.ClassCastException: PushCounter cannot be cast to java.applet.Applet
Tutorial on applet:
http://download.oracle.com/javase/tu...etStarted.html
- 05-12-2011, 10:34 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 64
- Rep Power
- 0
also,
you have not closed the applet tag...Java Code:<applet code="PushCounter.class" width="100" height="100"</applet>
- 05-12-2011, 10:51 PM #4
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
Thank you CultClassic. I was able to not get the error now, but it only displays a light gray box in the upper left corner of browser (I didn't place it). Any more help greatly appreciated. thank you. Here is my new code fixed with the extends applet and closed applet html tag.
HTML
Java file 1 (which I compile into a .class file)Java 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="" /> <link href="default.css" rel="stylesheet" type="text/css" /> <style type="text/css"> </style> </head> <body> <applet code="PushCounter.class" width="100" height="100"codebase="../pushcounter/"></applet> </body> </html>
Java file 2Java Code://******************************************************************** // PushCounter.java Authors: Lewis/Loftus // // Demonstrates a graphical user interface and an event listener. //******************************************************************** import javax.swing.JApplet; import javax.swing.JFrame; public class PushCounter extends JApplet { //----------------------------------------------------------------- // 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); } }
Java Code://******************************************************************** // PushCounterPanel.java Authors: Lewis/Loftus // // Demonstrates a graphical user interface and an event listener. //******************************************************************** import javax.swing.JApplet; 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); } } }
- 05-12-2011, 11:03 PM #5
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
I took out all the applet references and ran it at the command line and it works. It's a desktop app, not an applet, my mistake, thank you.
- 05-13-2011, 12:19 AM #6
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
Does anyone know how I can give my java app to someone on the internet and let them run it from their desktop instead of the command line please?
- 05-13-2011, 04:40 AM #7
Similar Threads
-
Signed Applet crashing FireFox in Ubuntu
By saurabhbatra in forum Java AppletsReplies: 1Last Post: 06-07-2010, 01:53 AM -
Java applets is not working on firefox
By yanran336 in forum Java AppletsReplies: 4Last Post: 02-18-2010, 01:19 PM -
display bar graph with the help of java applet
By ras_pari in forum Java AppletsReplies: 1Last Post: 12-15-2009, 01:18 PM -
How to display a java application using applet and XMl as backend in web page
By simple11 in forum Java AppletsReplies: 2Last Post: 04-26-2009, 06:36 AM -
How to force Firefox to reload applet
By JordashTalon in forum Java AppletsReplies: 3Last Post: 02-20-2009, 11:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks