Killing an applet inside a JPanel
Hello,
I have loaded an applet into a JPanel and I would like to simulate a page refresh with my code.
I have tried to call .stop() or .destroy() on my applet, it immediately crashes Java with a segmentation fault.
Code:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f5a87d6c520, pid=28733, tid=140026897590016
#
# JRE version: 6.0_29-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.4-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C 0x00007f5a87d6c520 _fini+0xf1c9acc8
I am wondering if there is any elegant way to perform this task?
Re: Killing an applet inside a JPanel
Related question: Is there a way to access the thread that the applet is running? I could try killing the thread if there was someway.
Re: Killing an applet inside a JPanel
Quote:
loaded an applet into a JPanel
Can you explain how you are executing the java program with the applet.
Is there a browser involved? How does the applet get to the AppletContext and AppletStub objects that are normally provided by a browser?
What GUI container is the JPanel loaded in?
Quote:
access the thread that the applet is running?
Which method(s) in the Applet are you talking about?
Re: Killing an applet inside a JPanel
Hello,
I build everything the Applet needs to run and create my own AppletStub. The applet normally runs in a browser, but I am not using a browser to launch the applet inside my JPanel.
I setup my params in a hash map, then I download my JAR using a JarURLConnection. I finally create the applet by using JarURLConnection.loadClass().newInstance().
Here is a link to my svn with the code on it: john5788 - Revision 35: /Supersonic
The loading of the applet is performed In the beginning of Supersonic.java, and subsequently, that is also where it is crashing when I attempt a refresh.
Re: Killing an applet inside a JPanel
Alright, I figured out its not my code that is crashing the JVM, it is the applet itself. Something is wrong with the applet when destroy or stop is called upon it.
New question: is there a way to spawn a new JVM for my applet so my program does not crash with the applet?
Re: Killing an applet inside a JPanel
Not sure what you are doing.
An JApplet is designed to be displayed in a browswer, not a JPanel.
See: How to Make Applets (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Re: Killing an applet inside a JPanel
Quote:
applet when destroy or stop is called upon it.
Are these the methods in your applet that are being called? Who calls those methods?
I'm not sure Why you are using the applet class? What benefit do you get if there is no browser?
Can you provide a SSCCE to show the problem. There are too many parts at the link you provided.
Re: Killing an applet inside a JPanel
The applet isnt owned by me. I am just creating a third party wrapper for the applet to add tools on top of the applet.
Here is my short example:
Code:
AppletLoader appletLoader = new AppletLoader();
appletLoader.buildApplet();
// Assume applet is loaded correctly in this example
Applet myApplet = appletLoader.getApplet();
JPanel panel = new JPanel();
panel.add(myApplet);
// Crash here
myApplet.stop();
myApplet.destroy();
I'm not sure if this example is good enough to understand. But as I stated in my last post, I've discovered why my Swing GUI crashes, it is due to the Applet doing something bad that I cannot control. My solution is to try and run the applet in a new JVM to allow that to crash without disturbing the rest of my GUI. Now I need some ideas for this
Re: Killing an applet inside a JPanel
Can you get the source for the applet and see what it is doing?
If you execute the applet in another JVM, what is the purpose of doing it? What results will you get from it?
You can always use the Runtime and Process classes to start another version of java.
Re: Killing an applet inside a JPanel
Ah, maybe I should have included in my example that I am running the applet in a new thread.
Even in the new thread, when the applet crashes, it takes down the entire JVM unfortunately. Maybe there is no fix for this.
Re: Killing an applet inside a JPanel
Look at the applet's source and see what it is doing.
Re: Killing an applet inside a JPanel
Quote:
Originally Posted by
John5788
The applet isnt owned by me. I am just creating a third party wrapper for the applet to add tools on top of the applet.
You could try to remove() the applet from the JPanel and add a new instance of it.
db
Re: Killing an applet inside a JPanel
You have two methods. Which method stop() or destroy() is causing the problem? As I understand applets stop() is invoked when the browswer loses focus so in case you applet does animation you can pause the animation. Then destroy() would be used when the browswer window closes to release applet resources. If you are trying to use this in an application then I would guess you don't need to use this method.
Since you haven't posted an SSCCE there is not much more we can do.