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....

Similar Messages

  • Why won't my iTunes code work

    Why won't my iTunes code work helpppp

    Hi Benrad09,
    If you are having issues redeeming an iTunes Gift code, you may find the following article helpful:
    Apple Support: If you can't redeem your iTunes Gift Card or code
    http://support.apple.com/kb/HT6021
    Regards,
    - Brenden

  • HT4972 Why won't Kindle or instagram work on my I-Touch? Why do either of them require IOS 4 or 5?

    Why won't Kindle or instagram Apps work on my I-Touch?
    Why do either of them require IOS 4 or 5 and why can't Itouch V2 update to IOS 4 or 5 operating systems?

    1. The developer stopped supporting older iOS versions.
    2. A second generation iPod touch can be updated to iOS 4.2.1 but doesn't have enough RAM to run iOS 4.3 or newer.
    (82591)

  • System.exit doesnt work on Sun OS 5.7 ??

    Hi, I have encountered a kind of wierd problem. I have a small application that uses System.exit when the user wants to shut down the application.
    That works fine in Windows but in Sun OS 5.7 the application just freeze.
    Im using java version:
    java version "1.4.1"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
    Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
    Would be greatful if someone could help me.
    This code is an small example of my application.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ExitTest extends JFrame implements ActionListener {
    JButton jButton1 = new JButton();
    public ExitTest() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    new ExitTest().setVisible(true);
    private void jbInit() throws Exception {
    jButton1.setText("Exit");
    jButton1.addActionListener(this);
    addWindowListener(this);
    this.getContentPane().add(jButton1, BorderLayout.SOUTH);
    public void actionPerformed(ActionEvent e) {
    this.setVisible(false);
    System.out.println("Exiting");
    try {
    System.exit(0);
    } catch(SecurityException ex) {
    ex.printStackTrace();
    ---------------------------------------------------------------------------------------------------------

    Hmm, sorry about that, my misstake, that line is still there from an erlier attempt to use windowlisteners instead ... that line should not be there ...

  • 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.

  • WHY WON'T STICKY KEYS ACCESSABILITY WORK ON SAFARI/

    WHY WON'T STICKY KEYS ACCESSABILITY FEATURE WORK ON SAFARI? I AM A DOUBLE AMPUTEE AND THIS FEATURE REALLY HELPS ME.
    RANDY

    Do us all a favor, and unlock your Cap keys.  It's considered yelling, and it's a real turn-off for those looking to help posters here.

  • Why won't my lock button work?

    I went to lock my iPod and my lock button won't work. I can't even push it down, it's like stuck down in the hole but it won't pop back up. Everything works fine but I have to wait for it to auto-lock everytime I want to turn it off. Why won't the button pop back up?

    It looks like you have a hardware issue. I don't know why the button doesn't pop up, but You can enable assistive touch. Assistive touch gives you a virtual lock button, so that will solve you problem. You can enable it by going to Settings->General->Accessibillity->AssistiveTouch->On.

  • Why won't my "if" expression work?

    This calculation works:
    IF(A3<1,A3*10,IF(A3<5,20))
    Why won't this one:
    if(A4<1,B4==0,if(A4>1<=2,40,if(A4>2<=3,60,if(A4>3<=4,100,if(A4>4<=5,125)))))
    If you want me to send you the table that I am trying to make this work in, just let me know. Thanks,
    Elaine.

    Never mind, I figured it out! Whew.

  • Why won't megapack for iworks work on my mac?

    Why won't my megapack for iworks work on my macbook pro?

    only pages will work and its crap...what a waste of money.

  • Why won't time capsule router work?

    Why won't the time capsule's wireless router work to allow internet access?  Just got it, new 2 tb!  Lost the excitement of it all now!  Help!  Connecting to new MacBook pros (13" &amp; 2X15"s) as well as a Toshiba laptop.  Followed all the directions and backed up just fine, but have not been able to browse web at all with this crap!

    You do not have to load the airport utility.. a newer version is already included on the computer.
    Just go to the applications / utility directory and start airport utility.

  • Why won't combined AND statement work

    I want to exclude records based on two criteria's: status = 'M' and the status reason = 52.
    The table contains records with status = 'M' and status reason other than 52.
    Also the table contains records with status other than 'M' and status reason = 52 and I want to include those records.
    I first tried using the statement below reasoning that placing the two criteria's in parenthesis would combine them and only exclude records with M 52
    Where (nvl(Status_CD,'A') <> 'M' AND nvl(STATUS_RESN_CD,0) <> 52 )
    However the query removed all records with Status_CD 'M' and all records with Status_Resn_CD 52. 
    Using the Where Not statement worked.
    Where Not (External_Status_CD = 'M' and EXT_STAT_RESN_CD = 52 ) 
    I’m curious why the first statement didn’t work?
    Can anyone explain why the first query didn't combine the 2 statements but a Where Not did?
    Thank you - Mark

    HI, Mark,
    markjames9 wrote:
    I want to exclude records based on two criteria's: status = 'M' and the status reason = 52.
    The table contains records with status = 'M' and status reason other than 52.
    Also the table contains records with status other than 'M' and status reason = 52 and I want to include those records.
    I first tried using the statement below reasoning that placing the two criteria's in parenthesis would combine them and only exclude records with M 52
    Where (nvl(Status_CD,'A') <> 'M' AND nvl(STATUS_RESN_CD,0) <> 52 )
    However the query removed all records with Status_CD 'M' and all records with Status_Resn_CD 52.
    Using the Where Not statement worked.
    Where Not (External_Status_CD = 'M' and EXT_STAT_RESN_CD = 52 ) 
    I’m curious why the first statement didn’t work?
    Can anyone explain why the first query didn't combine the 2 statements but a Where Not did?
    Thank you - Mark
    Another way of looking at it:
    The condition (x AND y) will be TRUE when both x AND y are TRUE.
    If
    sub-condition x is    nvl (Status_CD, 'A') <> 'M'   and
    sub-condition y is  nvl (STATUS_RESN_CD, 0) <> 52
    then any row with status_cd = 'M' fails sub-condition x, therefore the compound condition is FALSE, regardless of status_resn_cd.
    Likewise, and row with status_resn_cd=52 fails sub-condition y, so the compound condition is FALSE regardless of status_cd.
    You used status_cd and status_resn_cd in one example; but
    EXTERNAL_status_cd and EXT_stat_resn_cd in the other.  That's quite confusing.  Also, you'll confuse everyone (including yourself) if status is abbreviated as stat in some places but not in others.  Either way is okay, but be consistent.  The same goes for abbreviating external as ext; pick one or the other, and use the same word in all places.
    Don't forget to check for NULLs.  If  external_status_cd and ext_stat_resn_cd can be NULL, you should say
    Where Not (    NVL (External_Status_CD, 'A') = 'M'
              and  NVL (EXT_STAT_RESN_CD,    0)  = 52
    depending on your requirements.

  • Why won't logic 9.02 work with lion

    Why will logic 9.02 not work with Mac OSX Lion ????????

    The serial included with the TORRENT floating around the web for Logic 9 wont work on anything after 9.0.2
    $100 says this is why said user is freaking on a simple update... just sayin

  • Finally and System.exit()-Will work togother?

    Does finally block execute if we call System.exit() inside a try block?
    try{
    if(condition)System.exit(0);
    finally{
    System.out.println("Inside finally");
    If condition is true, will finally execute?
    When i tried it on jdk1.3, it's not executed.

    I'm pretty sure the finally{} block will never be executed. When calling System.exit(), it tells the application to terminate immediately. Here's something you could try, if you have code that needs to run if there's been an exception or not. Sorry for the horrible code conventions.
    boolean sysExit = false;
    try{
    if(condition){
    sysExit = true;
    catch(Exception e){
    //Do whatever.
    finally{
    //Do finally stuff
    if(sysExit) System.exit(status);
    }

  • Why won't my Apple applications work all of a sudden?

    For some reason over the weekend, my Apple applications like Safari, Mail, Software Update and such won't work. When I open one, my cursor turns into that rainbow circle and just stays there. The application won't go any further.
    However, my other applications I have seem to work fine, such as Adobe products, Macromedia products, and Internet Explorer.
    Do I need to reinstall my system? If I buy Tiger and install that, would that solve my problem as well? If I do reinstall my system, what files do I need to back up to save old emails?

    Alonzo,
    Welcome to Apple Discussions !
    Did you recently install a new application or printer/scanner?
    You might have a font conflict . . .
    Many times, fonts will mess up all he Apple apps but not affect 3rd party apps.
    If you haven't added anything containing additional fonts, let us know, and we can look into font book app for duplicates.

  • Why won't my Home Sharing work?

    I have a MacBook Pro running Lion.  Home Sharing is turned on and logged in on iTunes and iTunes is running, still I cannot access my computer's Library on my Apple TV (2 gen) which also has Home Sharing turned on and logged in..  It used to work every time, but recently it has decided not to load the Library.  I have not changed anything anywhere, either in my home network (Airport Extreme) or any system preferences.  I do not understand why this has happened. 
    Can anyone (especially Apple techs) give me a reason for this problem and advise how to fix it.  I would like very much to watch my iTunes Movies on my HDTV via Apple TV as I used to be able to do, but it just will not cooperate.

    I have done a comprehensive check on all my other devices (iPhone 4s, iPad mini, iPad (1) and all of those devices have NO problem with Home Sharing.  They all work as they are supposed to.  So, I decided to "reset" my Apple TV.  It seems to have worked.  I have now tried three different times with Appl;e TV and it worked each time. 
    Therefore, I would advise anyone else having problems with Home Sharing on an Apple TV to reset the Apple TV. You will of course have to reconnect to your Wi-Fi network and restart Home Sharing and enter your account information as well as other initial settings which Apple TV will prompt you for.  But it did work, at least for now.

Maybe you are looking for