File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Can I call System.exit() from an applet ? If so, how ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Can I call System.exit() from an applet ? If so, how ?" Watch "Can I call System.exit() from an applet ? If so, how ?" New topic
Author

Can I call System.exit() from an applet ? If so, how ?

Sunitha Sriram
Greenhorn

Joined: Jun 20, 2000
Posts: 4
I have an Exit button in an applet and the applet should exit when the user clicks on the exit button. I tried using System.exit(), but it throws Exception.
Nathan Paris
Greenhorn

Joined: Jun 21, 2000
Posts: 28
I am not sure that you want to try and stop the VM. Another way would be to send the browser to a different page when the exit button is hit. Therefore sopping the applet.
Nathan
Sunitha Sriram
Greenhorn

Joined: Jun 20, 2000
Posts: 4
That's what I have done as a temporary solution. It would be better if I can exit the VM, just like when a System.exit() is called from a window closing event.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
class demo extends Applet implements ActionListener
{
public void init(){
Button B1=new Button("rahul");
add(B1);
B1.addActionListener(this);}
public void actionPerformed(ActionEvent e)
{System.exit(0);
}

}
i tried the above .
when the button is pressed the action event System.exit is taking place.
however there is a runtime Security excepiton being raised in the console window.
Regds.
Rahul.

[This message has been edited by rahul_mkar (edited June 21, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi sunitha & rahul
it will raise an exception called runtimeexception .
u have to exit vm to exit from the applet.
for that u have to grant permission using policytool.
from the dos prompt enter policytool.
in that window add permission called runtime
& target as exitvm
save the file with extension .pol.come out & run the applet as
appletviewer -J-Djava.seurity.policy="filename.pol" appletfilename
it will work.thanks
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Iam not sure whether System.exit() will work when the Applet is embedded in a web-browser because ur trying to close the applet which is in turn embedded in a another container of the web-browser.And the web-browser will always have a window.The other way is to navigate to an another page there by stopping the Applet execution
Glen Tanner
Ranch Hand

Joined: Apr 16, 1999
Posts: 147

You can't use System.exit() without raising a security exception.
What you can do is call the applet destroy() method from the applet's stop().
So, create a stop() method which does any cleanup and calls destroy(). Then call stop() from your actionPerformed().
[This message has been edited by Glen Tanner (edited August 04, 2000).]
[This message has been edited by Glen Tanner (edited August 04, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I call System.exit() from an applet ? If so, how ?
 
Similar Threads
System.exit(0) applet
Exiting from Applet
add window listener on button
applets
Quit audio before application exits.