• Post Reply Bookmark Topic Watch Topic
  • New Topic

embed an applet into jpanel  RSS feed

 
Ashish Nandan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shrinath M Aithal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Rob Camick
Ranch Hand
Posts: 2801
15
 
Ashish Nandan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Shrinath,

I just have the applet... no control over it(in form of a jar file). Is there any other way?
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:I thought I'd quote myself.
That saves me the trouble of quoting Rob.
 
Shrinath M Aithal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!