• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing a applet by user prompt

 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,

I want to be able to execute an applet when the user clicks/selects a button on the webpage.
What would be the best approach to handle this? Ie javascript conditional statement or a conditional statement within the applet?

C
 
Maneesh Godbole
Saloon Keeper
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the user clicks call a servlet/jsp/whatever which will serve a page which has an applet embedded inside it
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but i was wondering if it is possible to
somehow execute the applet in the same webpage the user is currently viewing ...
 
Maneesh Godbole
Saloon Keeper
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you mean load when you say execute, then I think it should be possible. But you might have to use AJAX for that.
Disclaimer: I have not done it myself.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try to add a DIV to the page that has an applet tag in it.
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to try and run the applet in situ something like this with a div tag: <div onclick='<applet code=NameOfPackage.NameOfApplet archive=NameOfApplet.jar width=300 height=300>'

but from wat im reading i don't think the onclick event attribute supports applet elements
 
Maneesh Godbole
Saloon Keeper
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:You could try to add a DIV to the page that has an applet tag in it.

I am not sure I understand this approach. Won't the div element be loaded when the page loads? Where as the OP wants to load after some user action.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user action would trigger a piece of JavaScript that inserts the DIV/APPLET tag. So it only gets added to the page if that button is clicked.
 
Maneesh Godbole
Saloon Keeper
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Ok. I was completely thinking on the wrong lines. Thanks.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Where as the OP wants to load after some user action.


I'm not clear about why the OP would want to do that. What difference does it make if the applet is loaded along with the page or if it's loaded later? Why not let it load with the page into a hidden div and then just make it visible when the user clicks a button? Ciaran? Any comments?
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
I can see now either method has the same effect so i can now go ahead and try the invisible div approach.

Thanks all
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
So i have written my applet and it works on the apple viewer in netbeans but I cant get it to load on the web browser.
I have donwloaded Java 7 and enabled Java in security settings of both Safari and Firefox.
I cant see any errors on the web inspector so am at a bit of a loss.
The HTML file, applet.class and applet.jar are all on my desktop.
The HTML code is:


Thanks in advance
C
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what the "web inspector" is, but Java errors would show up in the Java Console.

"applet.class and applet.jar" - the files mentioned in the applet tag are different; just a copy/paste mistake?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the applet class and jar are on your desktop? Is that where the HTML code you posted says to download them from?
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thats correct, to check the directory was correct i loaded a image from the same directory as jar and class file, the image loads fine.
Ive tried this tutorial on netbeans https://netbeans.org/kb/docs/web/applets.html and hav read allot on the web but cant seem to get it.
This is my first applet, I must be doing something fundamentally wrong here, pulling my hair out at his stage

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic