aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Executing a applet by user prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Executing a applet by user prompt" Watch "Executing a applet by user prompt" New topic
Author

Executing a applet by user prompt

Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

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


I love deadlines, I love the whooshing sound they make as they fly by...
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10246
    
    8

When the user clicks call a servlet/jsp/whatever which will serve a page which has an applet embedded inside it


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

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

Joined: Jul 26, 2007
Posts: 10246
    
    8

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
Marshal

Joined: Mar 22, 2005
Posts: 41488
    
  52
You could try to add a DIV to the page that has an applet tag in it.


Ping & DNS - my free Android networking tools app
Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

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

Joined: Jul 26, 2007
Posts: 10246
    
    8

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
Marshal

Joined: Mar 22, 2005
Posts: 41488
    
  52
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

Joined: Jul 26, 2007
Posts: 10246
    
    8

Oh Ok. I was completely thinking on the wrong lines. Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 21, 2013
Posts: 72

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

Joined: Jan 21, 2013
Posts: 72

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
Marshal

Joined: Mar 22, 2005
Posts: 41488
    
  52
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 21, 2013
Posts: 72

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a applet by user prompt