wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes Deploying my Japplet in Netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Deploying my Japplet in Netbeans" Watch "Deploying my Japplet in Netbeans" New topic
Author

Deploying my Japplet in Netbeans

Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Hi everyone. I'm banging my head against the wall trying to figure this out.

I'm using NetBeans 6.9.1 and I have a project of type "Java Application." This project contains no Main method, but instead a Japplet named AlarmClock.java. When I right-click and run AlarmClock.java, it runs correctly with no problems. What I can't figure out is how to get this applet to run on a website (or even locally on my computer for that matter). I've tried building it and opening up *ProjectDirectory*/dist/launch.html which starts up launch.JNLP which opens up a webpage with a space for my applet, but this space just contains an error message.

I'm not sure if it's something wrong with my project settings, and I don't know what a "codebase" is or whether "Web Start" should be on. Do I need a main method that opens up my applet, and how would I do that? Some advice would be hugely appreciated.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Applets do not use a "main" method. See the javadocs of java.applet.Applet for the applet lifecycle methods you need to hook into.

But you mention "Web Start" and "JNLP", which is a method of starting applications -not applets-, and applications do use a main method. So is this supposed to be an applet or a WebStart application?
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
This is supposed to be an applet. I'm very lost as to how to get this applet onto a webpage. I figure this should be a pretty simple procedure, but I don't even know where to start. If I could get a simple step-by-step for how to get a working applet working on my webpage, that would help me out so much.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You'll need to write an HTML file that contains an APPLET tag. Start here: http://download.oracle.com/javase/1.4.2/docs/guide/misc/applet.html
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Kyle Xxxxxx wrote:

Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Lester Burnham wrote:You'll need to write an HTML file that contains an APPLET tag. Start here: http://download.oracle.com/javase/1.4.2/docs/guide/misc/applet.html


I used some code I found there to embed the applet in my webpage, but the applet opens up blank. I have the .class files in the same directory as my .html file, so I'm not sure what the problem is. Generally, what is my "code base?" Is it OK if I don't have one, or is that why nothing is showing up?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
As that page mentions, codebase is optional. In particular, you don't need it if the class files reside in the same directory as the HTML file. If you post the APPLET tag you're using, we can take a look at it.
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
I went with the simplest example they had. I'm just trying to get this thing to run.



The file AlarmClock.class is in the same directory as this file (launch.html), as well as another class that AlarmClock depends upon, and some .png images that are needed by the applet.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
That looks like it should work. Are there any error messages in the Java Console?
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Actually, yes. The java console gives this error:

java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at AlarmClock.init(AlarmClock.java:39)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.awt.AWTPermission setAppletStub)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.applet.Applet.setStub(Unknown Source)
at AlarmClock.initComponents(AlarmClock.java:96)
at AlarmClock.access$000(AlarmClock.java:20)
at AlarmClock$1.run(AlarmClock.java:41)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


I'm going to try what this guy says to do, however it doesn't let me modify the part of the code where "setStub" is. How do I tell netbeans to allow me to edit the fields it currently won't let me?

Thanks for all your help, by the way.
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Putting initComponents() outside of the try/catch statement makes it display an error message in my browser now. It seems like the error is caused by initComponents(), though that seems to cover practically everything. The permissions on all of my files are set to 777 (everyone can read, write, execute), so I don't know what they mean by "permissions."

I've also modified my code so it no longer uses external classes or png images, everything it needs to run is in the one file now (AlarmClock.java), and of course still runs when I click "run file" in netbeans.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The problem is the call to "setStub" - applets generally don't need to do that (and, as you found out, aren't generally allowed to do it). What does that part of the code do?
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Honestly, I don't know. This code is auto-generated by NetBeans, probably because I'm using some incorrect settings. My project is of type Java Application, maybe it should be of type Web Application?

The problem is that NetBeans won't let me modify that part of the code at all. I'll try some things to get rid of that. Should I change the project type, or just try using a plain text editor maybe?
Kyle Thornton
Greenhorn

Joined: Sep 13, 2010
Posts: 8
Oh man it's working! Commenting out setStub() made a world of difference. Thanks so much for helping me through this! I would've lost my mind tonight of not for you.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
I'm not much familiar with NetBeans, but both "Java Application" and "Web Application" sound wrong. Isn't there an option "Applet"?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deploying my Japplet in Netbeans
 
Similar Threads
null Pointer Exception from applet viewer
deploying applet
appletviewer
Pong
Applets fail to load in a browser