IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes embed an applet into jpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "embed an applet into jpanel" Watch "embed an applet into jpanel" New topic
Author

embed an applet into jpanel

Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
I have a unique problem. I have an application built on swing framework with xml used for design and maven used for build.
I have an applet that is independent of this application. Now i dont have a clue how to embed that applet into a jpanel or into that application. Anything of that will help me immensely. Please suggest if anybody has a clue.

Thanks in advance.

Regards,
Ashish


Regards,
Ashish Nandan
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
Can you embed an Applet into a panel? Applets are intended to be top-level containers. Have you tried putting everything in the Applet into a single Component (eg a JPanel which occupies the entire size of the Applet), then put that Component into your Swing GUI?
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

Campbell Ritchie wrote:Can you embed an Applet into a panel? Applets are intended to be top-level containers. Have you tried putting everything in the Applet into a single Component (eg a JPanel which occupies the entire size of the Applet), then put that Component into your Swing GUI?

Although you are right, you can add an Applet (and JApplet) into a Swing application. After all, Applet (and therefore JApplet) are Containers and Components.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Posts: 82
I dont see your exact requirement clearly in your question..

do you want to "embed" it or just invoke it?

In general, if you are willing to get the functionality of this particular applet into your application, I suggest you to invoke the applet through your app.. like import that applet's classes and just create instance and invoke it..


Regards
Shri..

SCJP 5.0
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1652
Be Forthright When Cross Posting To Other Sites
Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
Thank you for your replies.

Hi Campbell:

I want to put everything of the applet in a Jpanel and am not getting how to do it. Then I will put it into my GUI. The applet already exists and is independent of the Swing GUI. Any help on this will be highly appreciated.

Hi Shrinath,

Above mentiond is the exact requirement. Kindly go throgh and help if possible.
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Posts: 82
Ashish Nandan wrote:Thank you for your replies.

Hi Campbell:

I want to put everything of the applet in a Jpanel and am not getting how to do it. Then I will put it into my GUI. The applet already exists and is independent of the Swing GUI. Any help on this will be highly appreciated.



you want to put everything in applet to a JPanel.. Do you have that applet's source code? if yes, search for the lines where it adds all the components to applet container.. if you've already created a JPanel, start replacing those lines to add to JPanel.. add JPanel to main container.. thats it..

typically, the lines will be like x.add(alabel); etc.. where x is the applet's container and label is a normal label.. so if you want to place the same label into your swing jpanel, create a jpanel with any name, say panel , and replace x.add(alabel) with y.add(alabel);
if the class is extending from applet, then replace it with JFrame.. and add a line to add your jpanel to JFrame, like : this.getContentPane().add(y) where y is your jpanel..

hope that helps..
Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
HI Shrinath,

I just have the applet... no control over it(in form of a jar file). Is there any other way?
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

Rob Prime wrote:...you can add an Applet (and JApplet) into a Swing application. After all, Applet (and therefore JApplet) are Containers and Components.

I thought I'd quote myself.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
Rob Prime wrote:I thought I'd quote myself.
That saves me the trouble of quoting Rob.
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Posts: 82
Rob Prime wrote:...you can add an Applet (and JApplet) into a Swing application. After all, Applet (and therefore JApplet) are Containers and Components..


thats the only way..
or try if you get any "Decompilers"
I dont know if it is illegal to reverse engineer a program, but there is a way..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26710
You may not need to reverse engineer anything. If you unzip the .jar file, you can take all the classes, and add them to the new Panel. You may not get the correct Layout, but it is worth trying.

Rob's method is probably still quicker, however.
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Posts: 82
Campbell Ritchie wrote:You may not need to reverse engineer anything. If you unzip the .jar file, you can take all the classes, and add them to the new Panel. You may not get the correct Layout, but it is worth trying.

Rob's method is probably still quicker, however.


but if you reverse engineer with a layout, you'd get to change the layout too.. or just take the components and their actions..

@Ashish Nandan : Dude, please mind this.. if you are stealing something from that applet illegally, please drop the idea.. do it from scratch in your own way.. if you want help in that, dont hesitate to ask.. I dont mean to hurt you, sorry if I did..

Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
Dudes....

Its an official requirement. The applet is already there .... It was used in their previous versions... They have not given us the source code thats it and we have to develop this from scratch.

I had found a way... hope this goes well... need your help in knowing whether the approach is correct. Call that applet in a html file. read that file in editorPane and add that into jpanel.

I had tried this but all its showing a big question mark . Help me out guys please.
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

You still won't read my post, even after it contains, you know, a proper solution?

If you don't get the hint, here's some example code:
 
IntelliJ Java IDE
 
subject: embed an applet into jpanel
 
Threads others viewed
Repainting jPanel in Applet
Re: Embedding applet that takes dynamic input into JSP
Applet id name
Re: Embedding applet which takes dynamic input, into JSP
JApplet - Javascript communication
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture