aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JApplet within JInternalFrame...Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JApplet within JInternalFrame...Please help" Watch "JApplet within JInternalFrame...Please help" New topic
Author

JApplet within JInternalFrame...Please help

TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
I am having a problem. I am using JApplet as the only component inside JInternalFrame. It basicly wants to paint on top of everything else and makes everything else (including other jinternalframes) go crazy. I also noticed that the japplet is even painting over the japplet containing it. I would be extreamly greatfull (as would others doing the same thing) if someone knows a solution.
Some things I have tried:
1.
Override the paint method in your japplet class to call super.paint(some other graphics object besides the one passed). I tried this thinking that it would paint on the correct layer. Didn't work (or I havn't found the right graphics object). I have tried this with the Internalframe's graphic object and with the japplet's content pane. Didn't work. Am I on the right track???

------------------
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
My findings so far. JApplet is heavyweight because it extends Applet which extends Panel. I am going to try to make my own "LightWeight" applet class by making a copy of Applet.java and extending JPanel instead of Panel. I know that there has to be more to it than that but I think thats where I'll start.
I'll keep you guys updated. I KNOW others will benefit from this if it works.
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
You may be asking yourself, "Why would JApplet be heavyweight?". The answer: Lightweight components need to be contained by a heavyweight container. This means that the top level parent component needs to be heavyweight (as in JApplet, or JFrame). Otherwise the applet would be transparent and have no window (just a theory). In conclusion, the JApplet was never meant to be contained by a lightweight rich environment. It's either all or nothing.
I was also wondering why JInternalFrame works so well. TA'DA'...it extends JComponent, it is lightweight. So I would guess that if I made Applet to extend JPanel and added it to my JInternalFrame it would be equivalent to adding a JPanel to my JInternalFrame and it will work as designed.
I havn't done it yet because I had to put out a few fires.
[This message has been edited by TransZamboni (edited August 14, 2000).]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[I see you've already worked some of this out while I was composing this message at work, so some of this is repeating stuff you already know, but I'm too lazy to re-edit it now. - Jim]
I'm pretty sure you're on the right track that the problem is that you have a heavyweight component (JApplet) inside a lightweight one (JInternalFrame). Here's a useful article on heavyweight vs. light components. I've done very little work with applets myself, but I can't see any reason to have a an Applet or JApplet inside another component - the idea is that the (j)Applet is the outermost Java component. The applet is an interface between your Java program (on the inside) and a web page (on the outside). The only stuff outside the (J)Applet should be not Java stuff but rather the browser representation of the web page in which the applet is found. So I can't see any reason why your JInternalFrame should have any sort of Applet inside it - why not just replace the JApplet with a JPanel? What applet-like behavior are you trying to access inside your JInternalFrame? (Given that you already have one JApplet outside the JInternalFrame, right?)

"I'm not back." - Bill Harding, Twister
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
I now extend JPanel for Applet to get LightWeightApplet and, I now extend LightWeightApplet for JApplet to get LightWeightJApplet. I beleive this will solve the problem by providing a lightweight component (extends JComponent). What I am having trouble with is adding these new versions of the Applet and JApplet classes to the "java.applet" and "javax.swing" packages. I need the new files in there original packages because the original code used other package scope files. I have no idea where to add the new classes. What is the jar file that holds all the class files for these packages?
Jim,

The reason I have the JApplet inside of the jInternalframe is because our site's functionality is made up of many applets. It got very confusing very fast with a ton of browser windows open at the same time. We developed an "MDI" type of interface to solve that. Also the problem where netscape reloads your applet every time you resize is solved as well because we no longer open the applet inside the browser window but rather open it inside a JFrame. All this gives it a "real application" look and feel.
Another reason to do it this way is to avoid a lot of rewrite.

[This message has been edited by TransZamboni (edited August 14, 2000).]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I don't think this approach will work. You can't have a class which is both a javax.swing.JPanel and a javax.swing.JApplet, since both are classes, and Java does not allow multiple inheritance. It sounds like you plan to completely replace the official JApplet class with your own, which doesn't sound like a good idea to me. Your code will never be able to run on a standard JVM - you would always need to replace certain jar files with your edited versions. I suppose it could be done, but I'd hope you have complete control over all machines the client runs on, and this "feature" should be very well documented to any other coders who are to work in the environment, as it will confuse the heck out of anyone who doesn't realize you've altered the standard runtime environment.
I don't really understand your reasons for needing a JApplet inside the JInternalFrame, and still think you need to use something other than a JApplet. But as I said, I haven't really used applets that much - maybe there's something I'm missing here.
OK, if despite all my sermonizing you want to do this anyway, the JApplet class is probably in jre\lib\rt.jar under whatever directory you installed your jdk (at least for jdk 1.2.2 and 1.3). You can probably use WinZip or other zip utility to replace the JApplet.class - though you may need to use the jar command to get the manifiest right; I dunno. Good luck.
Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
WHOA! Hi Trans, I just seen your question link. I came to see if I could possibly take a whack at your question but we should probally change titles. The most I've done is draw a Chart and am waiting to make it handle events. I am glad to see that you are cracking it.
hope to be in your shoes someday, Steve
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
Originally posted by Jim Yingst:
I don't think this approach will work. You can't have a class which is both a javax.swing.JPanel and a javax.swing.JApplet, since both are classes, and Java does not allow multiple inheritance.

nope,
Applet (new class name "LightWeightApplet") will extend JPanel. JApplet (new class name "LightWeightJapplet") will extend LightWeightApplet. So, you see, I am not replacing. I am adding a new extention to the javax and java packages.

It sounds like you plan to completely replace the official JApplet class with your own, which doesn't sound like a good idea to me. Your code will never be able to run on a standard JVM - you would always need to replace certain jar files with your edited versions. I suppose it could be done, but I'd hope you have complete control over all machines the client runs on, and this "feature" should be very well documented to any other coders who are to work in the environment, as it will confuse the heck out of anyone who doesn't realize you've altered the standard runtime environment.

see above comment

I don't really understand your reasons for needing a JApplet inside the JInternalFrame, and still think you need to use something other than a JApplet. But as I said, I haven't really used applets that much - maybe there's something I'm missing here.

There are about 7 applets completely working and make use of JApplet features. I suppose we could make them all JPanels instead of JApplets. But then we would have to re invent the wheel and add JApplet features to JPanel. Can you see the logic now? It is the least pain in the a$$ of all the options we had.

OK, if despite all my sermonizing you want to do this anyway, the JApplet class is probably in jre\lib\rt.jar under whatever directory you installed your jdk (at least for jdk 1.2.2 and 1.3). You can probably use WinZip or other zip utility to replace the JApplet.class - though you may need to use the jar command to get the manifiest right; I dunno. Good luck.

I figured out last night (I think) that all I need to do is distribute a java.jar and a javax.jar and the the jvm will recognize it as part of those packages. I hope it works.

[This message has been edited by TransZamboni (edited August 15, 2000).]
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
Damn! The odds are against me. I can't have a package called java.swing or java.applet , JVM wont allow it.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
OK, LightWeightApplet is not really an Applet at all, but a Panel which mimics some of the behavior of an Applet. And likewise the LightWeightJApplet is not really a JApplet, but a JPanel which acts like a JApplet. Got it. I thought you were trying to do something else, which made no sense to me. So now why would you need to put the new classes to be in an existing standard package? Just make a new package and put them there. Or re-use an existing package of your own, which your existing code already imports (or is part of). You need to edit the existing code to refer to LightWeightApplet and LightWeightJApplet anyway - adding or modifying the import statements is pretty trivial.
But if for some reason you really want to make it look like your new classes are part of swing, the correct package name would be javax.swing. The JVM does allow this - it's only java.* that's disallowed it appears.
TransZamboni
Greenhorn

Joined: Jun 01, 2000
Posts: 19
This will not work.
Reason #1. I cannot load my javax.swing as part of the javax.swing package. I get loaded at a separate time and will remain separate. I was hoping the class loader and jvm would recognize they have the same package name and merge (automagicly) the two together.
Reason #2. The reason I had to put the new LWJApplet class in the javax.swing package is because the original JApplet (which is what I made a copy of) uses classes and methods which have only package scope and can't be accessed outside the package.
Reason #3. Then I thought .oO(oh that�s simple enough, I'll just copy and modify the classes that it needs and put them inside my own package). After about 50 classes deep I gave up. It was like a freaking tree that wouldn't stop.
wish me luck, off to plan "B".
-Trans "soon to be master of swing" Zamboni

[This message has been edited by TransZamboni (edited August 16, 2000).]
[This message has been edited by TransZamboni (edited August 16, 2000).]
Sam I-am
Greenhorn

Joined: Aug 02, 2004
Posts: 1
I don't understand what feature of JApplet you think you need to use. Why not use a JEditorPane for rich web content. That way you can load real JApplet s from there. The problem with what you're doing is not just that JApplet is a heavyweight component -- that's a big enough problem -- or that you're trying to alter the face of java; you forgot a very important aspect of this exercise, the security model and the browser JVM that enforces it and powers ther JApplet. Are you going to redo that? Are going o violate other important restriction on JApplets?

The only thing I can think of about JApplet makes it unappealing. It is restrictive. And it has nothing to offer other than the ability to run from a browser. And you can create a rich and powerful browser using JEditorPane.

Just trying to help.

Sam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JApplet within JInternalFrame...Please help
 
Similar Threads
knapsack, towers of hanoi, v. stuck!
Show wait box while executing database query
converting into applet
Why is screen flashing when I call repaint()?
Having two problem on paint