• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deploying my Japplet in Netbeans

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kyle Xxxxxx wrote:


Please check your private messages for an important administrative matter.
 
Kyle Thornton
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks like it should work. Are there any error messages in the Java Console?
 
Kyle Thornton
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not much familiar with NetBeans, but both "Java Application" and "Web Application" sound wrong. Isn't there an option "Applet"?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic