[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

embed an applet into jpanel

Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Messages: 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
Bartender

Joined: Oct 13, 2005
Messages: 14952

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 Prime
Bartender

Joined: Oct 27, 2005
Messages: 8788

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
Messages: 74

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..

This message was edited 1 time. Last update was at by Shrinath M Aithal


Regards
Shri..

SCJP 5.0
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Messages: 682

Be Forthright When Cross Posting To Other Sites
Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Messages: 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.

Regards,
Ashish Nandan
Shrinath M Aithal
Ranch Hand

Joined: May 20, 2009
Messages: 74

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..

This message was edited 1 time. Last update was at by Shrinath M Aithal


Regards
Shri..

SCJP 5.0
Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Messages: 22

HI Shrinath,

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

Regards,
Ashish Nandan
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8788

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.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14952

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
Messages: 74

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..

This message was edited 1 time. Last update was at by Shrinath M Aithal


Regards
Shri..

SCJP 5.0
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14952

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
Messages: 74

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..

This message was edited 1 time. Last update was at by Shrinath M Aithal


Regards
Shri..

SCJP 5.0
Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Messages: 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.

Regards,
Ashish Nandan
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8788

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:

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
MyEclipse Enterprise Workbench

.