Why isn't System.exit(0) used from an Applet

I am trying to figure out why the System.exit(0) method isn't used for an applet. Is it because an applet isn't an application (which is why the public static void main(String args[]))?
I have noticed when if I include System.exit(0) I will get an compilation error.
Is there someplace in the Java Tutorial that explains this?
thanks

You can put it in, but if you run it in a browser, it
will kill the browser and all its windowsThat is if the applet is signed. I have also noticed this behaviour and I think it is pretty weird. It looks like a bug to me.

Similar Messages

  • Why won't System.exit(0)  work?

    does System.exit(0); work with an event handler?
    I'm making a quit menu button, and I want my program to quit when it is clicked...unfortunately, System.exit(0); is not working...can soemone please help?
    thanks!

    here's all mmy code......i'm really at a loss...i can't figure anything out......
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    public class SafetyMapView extends JFrame {
         // These are the tiles and buttons
         private JPanel               tiles;
         private JButton[]          buttons;
         private JCheckBox           editWallsButton;
         private JCheckBox           selectExitsButton;
         private JButton           computePlanButton;
         private JCheckBox           showDistancesButton;
         private JButton           resetButton;
         private JMenuBar          theMenuBar;
         private JMenu               fileM;
         private JMenuItem          openM,saveM,quitM;
         private JFileChooser      showIt;
         public void setJMenuBar(JMenuBar aMenuBar){theMenuBar=aMenuBar;}
         public JButton getFloorTileButton(int i) { return buttons; }
         public JPanel getTilePanel() { return tiles; }
         public JCheckBox getEditWallsButton() { return editWallsButton; }
         public JCheckBox getSelectExitsButton() { return selectExitsButton; }
         public JButton getComputePlanButton() { return computePlanButton; }
         public JCheckBox getShowDistancesButton() { return showDistancesButton; }
         public JButton getResetButton() { return resetButton; }
         public JFileChooser getJFileChooser() { return showIt; }
         public JMenuItem getOpen() { return openM;}
         public JMenuItem getSave() { return saveM;}
         public JMenuItem getQuit() { return quitM;}
         // This constructor builds the panel
         public SafetyMapView(String title, FloorPlan floorPlan) { 
              super(title);
              // Create the panel with the floor tiles on it      
              createFloorPlanPanel(floorPlan);
              // Layout the rest of the window's components
    setupComponents();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(600, 500);
    setVisible(true);
    // Create the panel to contain the buttons that display the floor plan
    private void createFloorPlanPanel(FloorPlan floorPlan) {
         // Setup the panel with the buttons
    buttons = new JButton[floorPlan.size()*floorPlan.size()];
    tiles = new JPanel();
    tiles.setLayout(new GridLayout(floorPlan.size(),floorPlan.size()));
              // Add the buttons to the tile panel
    for (int r=0; r<floorPlan.size(); r++) {
         for (int c=0; c<floorPlan.size(); c++) {
              int i = r * floorPlan.size() + c;
              buttons[i] = new JButton();
              buttons[i].setBorder(BorderFactory.createLineBorder(Color.lightGray));
              buttons[i].setBackground(Color.white);
              tiles.add(buttons[i]);
         public void setOpenHandler(java.awt.event.ActionListener x){
         /*public void setSaveHandler(java.awt.event.ActionListener x){
                   int option = 0;
                   java.io.File sel = null;
                   java.io.File[] files = null;
                   String filename = null;
                   javax.swing.JFileChooser chsr = new javax.swing.JFileChooser();
                   option = chsr.showSaveDialog(null);
                   switch (option)
                   case javax.swing.JFileChooser.APPROVE_OPTION :
                   //do something
                        a.dispose();
                        break;
                   case javax.swing.JFileChooser.CANCEL_OPTION :
                   sel = null;
                   break;
                   case javax.swing.JFileChooser.ERROR :
                   sel = null;
                   break;
                   default :
                   sel = null;
                   break;
                   chsr.setEnabled(false);
                   //do something
                   return;
                   //DO something...//
    // Here we add all the components to the window accordingly
    private void setupComponents() {
         // Layout the components using a gridbag
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints layoutConstraints = new GridBagConstraints();
    getContentPane().setLayout(layout);
    // Add the tiles
    layoutConstraints.gridx = 0; layoutConstraints.gridy = 1;
    layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 7;
    layoutConstraints.fill = GridBagConstraints.BOTH;
    layoutConstraints.insets = new Insets(2, 2, 2, 2);
    layoutConstraints.anchor = GridBagConstraints.NORTHWEST;
    layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0;
    layout.setConstraints(tiles, layoutConstraints);
    getContentPane().add(tiles);
    JMenuBar myMenuBar = new JMenuBar();
    layoutConstraints.gridx = 0; layoutConstraints.gridy = 0;
    layoutConstraints.gridwidth = layoutConstraints.gridheight = 1;
    layoutConstraints.fill=GridBagConstraints.NONE;
    layoutConstraints.insets = new Insets(2, 2, 2, 2);
    layoutConstraints.anchor = GridBagConstraints.NORTHWEST;
    layoutConstraints.weightx = 0.0; layoutConstraints.weighty = 0.0;
    layout.setConstraints(myMenuBar, layoutConstraints);      
              JMenu fileMenu = new JMenu("File");
              myMenuBar.add(fileMenu);
              fileMenu.setMnemonic('F');
              JMenuItem openM = new JMenuItem("Open Floor Plan");
              fileMenu.add(openM);
              openM.setMnemonic ('O');
              JMenuItem saveM = new JMenuItem("Save Floor Plan");
              fileMenu.add(saveM);
              saveM.setMnemonic ('S');
              JMenuItem quitM = new JMenuItem("Quit");
              fileMenu.add(quitM);
              quitM.setMnemonic ('Q');
              getContentPane().add(myMenuBar);
    public static void main(String args[]){
         //try{
         new SafetyMapView("Fire Safety Routes", FloorPlan.example1());
         //catch(java.io.FileNotFoundException e){
         //     e.printStackTrace();
    I cut out the parts where all the other buttons are being added to the layout cuz it was really relaly long....

  • WHY can't I access my database from an applet???????????

    The security code won't let my applet access its own database (from its own server)..
    I'm using getDocumentBase()
    to try and tell it that it is my own damn file..
    I keep getting :
    java.securityAccessControlException: access denied <java.util.PropertyPermission jdbc.drivers write>
    ...etc.
    This applet crap is really starting to piss me off. I can see why they came out with JSP.
    All I need to do is access my database, update it, etc. It kind of defeats the purpose of being able to do jdbc from applets if you can't even access the database on your own damn server.
    If you all don't have a clue, I'm freakin switching to PHP--I'm tired of this crap-I was thinking Java was a damn good language until I hit applets.

    The simple answer to your question is: Because of security concerns.
    The somewhat longer answer is that directly accessing a database from an applet is generally not a good idea. A lot of security-critical code like DB username/password must be hidden in the applet which potentially can be downloaded (and disassembled) by anyone that hits your webpage. Maybe you do an intranet solution with trusted users but that is not what applets were originally designed for.
    The clean way is to make your applet talk to a servlet that talks to your database.
    If that is not the way you want to do it, make sure that all client policy files (yes, on the browser machine) contain the permissions that your applet needs.

  • Why isn't the DefaultItemRenderer class inherited from Skin?

    \sdks\4.0.0\frameworks\projects\spark\src\spark\skins\spark\DefaultItemRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <!--- The default skin class for a Spark DefaultItemRenderer class. 
          @langversion 3.0
          @playerversion Flash 10
          @playerversion AIR 1.5
          @productversion Flex 4
    -->
    The DefaultItemRenderer.mxml is skin class for ItemRenderer.cs,but isn't inherited from  skin?

    And to clarify one more thing, we also thought about making item renderers skinnable components (i.e.-ItemRenderer extends SkinnableComponent).  This way, everytime you were changing the look and feel of a component in Spark, you'd be following the exact same pattern.  But after we thought about it some more, that SkinnableComponent-Skinning model didn't really feel right here.
    With a SkinnableComponent we have a clear separation of the component properties and behavior on one side and the look and feel of the component on the Skin side.  Also, there's a clear contract we use to talk back and forth to one another.  The reason for the separation between the Skin and the SkinnableComponent is so that we can have one Button SkinnableComponent and multiple Skins for that Button which all tweak the visual appearance of it.
    It doesn't make sense for every component to be skinnable.  If you know what you're component is going to be and look like and don't need the extra flexibility skinning provides, then you can get rid of the extra overhead that skinning requires (like having 2 classes).
    With an ItemRenderer, we don't really need that separation and extra complexity.  It's really rare for someone to want to create an ItemRenderer component for a particular piece of data and want to have a separate Skin file for that ItemRenderer's look and feel.   For item renderers, the user really wants to create a custom item renderer with any extra behavior and the look and feel of the component all baked in to the same class.  Because of this, when you're creating a custom item renderer, you extend ItemRenderer, like:
    <s:ItemRenderer focusEnabled="false"
        xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
        autoDrawBackground="true">
        <s:Label id="labelDisplay" verticalCenter="0" left="3" right="3" top="6" bottom="4"/>
    </s:ItemRenderer>
    In general, if you want to build a custom component that isn't skinnable, you'd probably just extend Group (similar to our custom item renderer) and bake the child components and look and feel of the custom component right in.  If you want more flexibility and to build a new skinnable component, then you'd extend SkinnableComponent and create a default Skin for its appearance.
    Hope that helps,
    Ryan

  • Why isn't there a "Get Files from Zip" on the zip pallette in 8.0?

    The zip pallette has three functions.  New Zip File, Add File to Zip, and Close Zip File.  I cannot figure why they would not include a way of extracting files from an existing zip. 
    All three have password protected block diagrams, so I cannot go monkeying around on my own.  Anyone have any ideas?

    The OpenG add-on LabVIEW library (which uses zlib) will do all that you ask and more.
    The installation process uses something called OpenG Commander and, while it can be a bit confusing, it is more than worth the trouble in the end!

  • I had all the adobe products on my old laptop and it broke, but i backed up the harddrive. why isn't it letting me use any of my adobe products!?

    I'm so frustrated. My laptop overheated or something a few months ago, and i took it to a repair shop and he saved my hard drive. and I finally got a new macbook pro, and i have my old hard drive plugged in and dragged all my applications over. I tried editing a photo with photoshop, and it said "error 16: please uninstall and reinstall the product. If this problem still occurs, please contact technical support for help, and mention the error code.... "
    what would uninstalling it and reinstalling it do? would i love everything or have to pay for it again? I'm a recent art student graduate, and i cannot afford getting the adobe products again and they're all on my computer, just not working. What do I do?

    You can download CS6 from this link.  Use your current serial # to license it.
    Download CS6 products
    If you registered your product online (as you should have), you can find your product serial # by logging into MyAdobe with your Adobe ID (e-mail) and password.
    https://www.adobe.com/account.html
    Adobe ID, sign in, and account help
    Nancy O.

  • Why is my system serial number different from what Apple has?

    my system serial# W87****UX but Apple says it's MA5****x/A. anyone know why?
    <Edited by Host>

    You're doing fine..... now I took your serial number (before the hosts obliterate it) and input it here:
    http://support.apple.com/specs/
    and got this:
    http://support.apple.com/kb/SP28
    You'll see several different ones listed; one of them has your model number....
    Edit: good thing I did the above before the hosts got to your post - your serial number is no longer recognizable....

  • Why isn't my friend reciveving messages from I messages

    hi fix my problem plz

    Only Apple devices can receive messages sent through iMessages.  Your iPhone will only send a message through iMessages if it already knows that the other end of the connection is an iPhone and can receive such messages.  This is because a message sent through iMessages to a phone that could not receive it would just disappear without either of you knowing why.
    You can specifically chose to use iMessages to send a message to the other person's phone.  Once the message has been received by the other end both ends will know that the other end is an iPhone and they will use iMessages by default in future.

  • Calling System.exit() from multiple threads

    Hi,
    Why would calling System.exit() from multiple threads cause all the threads to block?
    Laith

    Thanks for your replies.
    I made further tests and the problem is actually not as I described it first.
    I'm using a shutdown hook that would stop all running threads if the program is stopped externally (using ctl-c for example) (I'm not using Thread.stop(), but setting a boolean value to false that would make the thread exit a while() loop in run()) .
    One of the running threads would call System.exit(-1) just before it would exit run().
    This thread is getting blocked if it is stopped by the shutdown hook.
    I know that this is a bad coding practice, bout would still appreciate an explanation to the reason why the thread is actually blocked by System.exit().
    Laith

  • JVM 1.5 hang at system.exit(): how to debug ?

    Our Java application seems to sometimes hang indefinitely at System.exit().
    So far, we have observed that:
    - the hang does not happen when running JDK 1.4, but only with JDK 1.5 (we are trying to migrate to JDK 1.5.0_06)
    - it seems that if we comment out code that calls PrinterJob.print(), the hang does not happen
    - the hang can be observed on all our machines (different models), except one that is misteriously not impacted. OS is WinXP SP2.
    - when our software has sent a printer job to the printer and is running JDK 1.5, the problem can be reproduced after at most 4 or 5 tries, usually 1 or 2 runs being sufficient.
    - we have not been able to narrow the problem to a simple testcase (only reproduced using automated testcases on our application, which is 200.000+ LOC....)
    - when the JVM is stuck in System.exit, the process can be killed using the task explorer with the usual "program does not respond" and subsequent "send problem report" wizard after having killed it. (not to sure on exact wording in english...).
    We suspect a hard-to-hit regression or behavior change in JDK1.5 (there's no reason a java application could hang at System.exit(), right ?), but the above information is certainly far from being sufficient to open a bug report.
    So, any help to help us further identify the problem would be appreciated.
    More precisely, is there any way to try to understand the problem using a crash dump, or something like this ?
    Thanks

    I doubt that it hangs at System.exit(). Use jConsole (comes with your JDK) to connect to your application and inspect all running Threads which block at what exception stack trace.

  • Catching System.exit() or How to avoid System.exit() - Third Party Tool ???

    Hi All,
    I am using a third party tool which is internally calling System.exit sometimes and my application
    got terminated most of the times.
    It is happening always when i call a particular method of that third party tool.
    Is there any way to catch or avoid the System.exit while using the particular method?
    I need this urgently...Please kindly help.....
    Thanks,
    J.Kathir

    There's a fair bit to it, and you should refer to the appropriate java Tutorials. Bascially you create a .policy file and install a sercurity manager with:
    System.setSecurityManger(new SecurityManager());The policy file grants a set of permissions to various "code sources", basically each codesource is a classpath entry. You could grant "AllPermissions" to your own code, and a more restricted set of permissions to the application you're running. But you can't subtract permissions, i.e. you can't say "this code can do anything except call System.exit().
    I doubt this is going to provide you with a good solution. It's tiresome to set up, and when the client app called System.exit it would crash, which might not result in a clean status.
    I'd consider if you should be using this client app in the same JVM, rather than creating a subordinate JVM using Runtime.exec.

  • Just updated my photoshop cc and wanted to try out the new focus selection tool but it's not there.  Why isn't it there?

    Just updated my photoshop cc and wanted to try out the new focus selection tool but it's not there.  Why isn't it there?

    Use menu Help>About Photoshop make you have started CC 2014 and have not started CC... Its in menu Select under Color range

  • I have deleted all emails from my ICloud email account but my manage storage still shows that the mail is using 9.7GB.  Why isn't the number decreasing if all emails have been deleted?

    I have deleted all emails from my ICloud email account but my manage storage still shows that the mail is using 9.7GB.  Why isn't the number decreasing if all emails have been deleted?

    It might be caused by storage "buffering".  If so, the space will adjust automatically when another iCloud feature uses the space previously allocated to your deleted email.  See http://support.apple.com/kb/HT4873.

  • I upgraded to PSE 13 so I could edit RAW files from my Sony a6000 but PSE 13 is not recognizing any of the RAW files. My Sony a6000 is on the Camera Raw list and uses version 8.4. PSE 13 uses Version 8.6. Why isn't it recognizing the files?.

    Why isn't PSE13 recognizing my Sony a6000 RAW files?

    Not sure if upgrading to 8.7 would make any difference.  Photoshop has 8.7 so worth a try:
    I don't use PSE13 yet so don't know if this upgrade is available for it.

  • System.exit(int) and javac def-use calculation

    I'm wondering if anyone can tell me why javac (J2SE v1.4.2) seems to ignore "System.exit(int)" (alternately, "Runtime.getRuntime().exit(int)") for the pursposes of determining possible variable access before an initialization.
    For example, consider the following code:
    /*01*/  public class C {
    /*02*/    public void foo() throws Exception {
    /*03*/      C obj;
    /*04*/      while (true) {
    /*05*/        try { obj = new C(); }
    /*06*/        catch (Exception fault) { System.exit(1); }
    /*07*/        obj.foo();
    /*08*/      }
    /*09*/    }
    /*10*/  }Compile this (ignoring the absurdity of what "foo()" actually does), and you will get a variable obj might not have been initialized error. This despite the fact that a call to "System.exit(int)" never returns normally, by definition. To illustrate why this error doesn't make sense, substitute the "System.exit(1)" of line #6 with any of "break", "return", or "throw new Exception()". The use calculation for variable 'obj' is correct in these three alternate situations, but not for the first, even though the situation is analagous.
    Obviously, there is an easy work-around to this (viz., change line #3 to "C obj = null;"), though it seems unnecessary. Any ideas?

    System.exit() doesn't have the same "special" meaning
    to the compiler as "break", "return", or "throw" do.
    As far as the compiler sees, you are simply calling a
    method in your exception handler; it doesn't know
    that there will be no return from that method. Sure,
    the compiler could special-case System.exit(), but
    then you'd still see this same problem if you came up
    with your own wrapper method that calls
    System.exit().. the compiler in general doesn't (and
    shouldn't) assume that a method call will terminate
    the app.I understand that "System.exit(int)" is merely a method from the perspective of the compiler, but it is a rather special method (actually the "Runtime" version, for which the "System" version is merely a wrapper) with respect to correct program execution, calculated during the various traces that are done during compilation. And wrapping "System.exit(int)" with another method wouldn't make any difference to the calculation if it was considered, from the perspective of compilation, an uncaught (implicitly declared non-Runtime) exception. Besides, there must be some execution sequence within "Runtime.exit(int)" that serves, essentially, the same function as an "exit" keyword.
    What's wrong with supplying a default value when you
    declare the variable?Absolutely nothing, except that it isn't necessary. I typically do so anyway, and only came across this "feature" of javac during a lapse of my coding standards.

Maybe you are looking for