aspose file tools*
The moose likes Applets and the fly likes Java applet won't display in firefox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Java applet won Watch "Java applet won New topic
Author

Java applet won't display in firefox

derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
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
__________________________________________________ __________


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.



and here




I have also posted this question http://www.java-forums.org/java-applets/43963-java-applet-wont-display-firefox.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

I think you'll find that class won't display as an applet in any browser at all. That's because it isn't an applet. At the very minimum a class must "extend Applet" to be an applet, and yours doesn't.

Not to mention it doesn't have any method which sets up the GUI, so even if you did change it to extend Applet, you still wouldn't see anything. I would suggest you read something about writing applets before you start trying to write an applet. You seem to be programming based on assumptions only.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

As Paul says, they're not applets - you have here a desktop Swing app. You need to compile them with javac, then run the PushCounter class from the command prompt (or your IDE if you're using one).
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Thank you. Luigi Plinge that cleared it up for me. It works now THANK YOU!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Aha... so I had it backwards. You didn't really want an applet at all. Anyway it seems you're straightened out now.

Which leads me to suspect: are you working from a book where writing applets appears in the first few chapters? They used to write them that way back in the last century, when people thought that applets were going to be more useful than they actually turned out to be. So if you're using a book like that, then it's almost certainly outdated and you should toss it immediately and get a more recent book. Applets should come near the end of the book, if at all.
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
haha. Well my book is from 2009, and they have 2 applets in an 800 page book, one in the beginning and one at the end. I was wondering, how do you make text games in a browser with java? can you do that with java? I want people to be able to see my progress as I am learning java, but all they give me in my book are console run apps, and gui desktop apps. I want to make web based little games as I learn. Any more help greatly appreciated. thanks. Derek
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

The easiest thing would be just use a console like the book tells you. If you want to do it via a browser, you'd have to design an applet to have a text display area and a text input area, which probably wouldn't be that difficult, but you'd need a bit of experience with applets and awt. AFAIK no-one has coded any sort of emulator to have text I/O in an applet that looks and behaves like it would in a console.
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Thank you. Is there another language that I could program web based games in please? Hopefully one similar to java so I have some experience when switching. Thank you! Derek
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
derek smythe wrote:Thank you. Is there another language that I could program web based games in please? Hopefully one similar to java so I have some experience when switching. Thank you! Derek


Yes ActionScript, it's very similar to java even the syntax is almost identical. It's used to create flash movies and games. From my limited experience with its I've learned that it relies heavily on events and delicates. When making flash games you'll be using four dimensional drawing toolkit supported by ActionScript.

If you want to make browser applications such as this lovely forum for example, you'll be using something like Php or it's java counterpart Jsp or Asp which is developed by Microsoft, Php is the most popular though. Most browser applications are supported by client-side scripts such as Javascript, client-side scripts don't need to be executed by a server, you can write a Javascript and execute it directly via html document in a local folder, you don't even need internet connection.
Even though it's called Javascript, it isn't very similar to java and is hardly object orientated language.
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Awesome thank you Unnar. Also, do you 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? As it is now I can only run my apps as .java files from the command line, even if it has a swing gui. But my friend can't see any of my progress because it isn't like an exec file that I can just mail him. Please any more help GREATLY appreciated. I've been wanting to do this since I started about a month ago, to share my work. Thank you! Derek
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
derek smythe wrote:Awesome thank you Unnar. Also, do you 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? As it is now I can only run my apps as .java files from the command line, even if it has a swing gui. But my friend can't see any of my progress because it isn't like an exec file that I can just mail him. Please any more help GREATLY appreciated. I've been wanting to do this since I started about a month ago, to share my work. Thank you! Derek


Maybe the easiest way is to make a batch file that includes the line java MyApp but you can put it in a jar bundle which is similar to zip except it is executable, much like an exe, but you need to specify an entry point i.e where the main function is located.
More info here
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Please any more help with the executable jar please. I made the jar file but it doesn't run on the double click.


Main-Class: PushCounter

in the Manifest.txt file


Here is what I did on the command line.


C:\JAVA_PROGRAMMING_CODE\code1\pushcounter>jar cvfm PushCounter.jar Manifest.txt
*.class
added manifest
adding: PushCounter.class(in = 657) (out= 431)(deflated 34%)
adding: PushCounterPanel$1.class(in = 199) (out= 152)(deflated 23%)
adding: PushCounterPanel$ButtonListener.class(in = 1084) (out= 572)(deflated 47%
)
adding: PushCounterPanel.class(in = 1527) (out= 790)(deflated 48%)

C:\JAVA_PROGRAMMING_CODE\code1\pushcounter>



Contents of my manifest are this below


Main-Class: PushCounter
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
I just ended the manifest.txt with a few empty carriage returns to make a few blank lines. Saved it, and recompiled. Here is the log of what I did at the command prompt,. I want to get this running so bad LOL. It just won't run. Notice the "unable to load manifest info" when I even try to run it at command prompt.



C:\JAVA_PROGRAMMING_CODE\code1\pushcounter\classes >jar -cvmf manifest.txt PushCo
unter.jar *.class
added manifest
adding: PushCounter.class(in = 657) (out= 431)(deflated 34%)
adding: PushCounterPanel$1.class(in = 199) (out= 152)(deflated 23%)
adding: PushCounterPanel$ButtonListener.class(in = 1084) (out= 572)(deflated 47%
)
adding: PushCounterPanel.class(in = 1527) (out= 790)(deflated 48%)

C:\JAVA_PROGRAMMING_CODE\code1\pushcounter\classes >java -jar PushCounter.jar
Failed to load Main-Class manifest attribute from
PushCounter.jar

C:\JAVA_PROGRAMMING_CODE\code1\pushcounter\classes >
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
I got it to work. thanks
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

You have very lucky friends!
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
haha. thanks. They are really going to love my brain cell counter app. Newbie power.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
derek smythe wrote:..I want to make web based little games as I learn. ..


The easiest option (if you can make a JFrame based game) is to launch it off the web using Java Web Start. It would require making an (XML format) JNLP file to launch the app. Then simply write a link in a web page using deployJava.js.


Andrew Thompson
http://pscode.org/
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Great thank you Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java applet won't display in firefox