• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic