System.exit(o) in Swing

Hi,
In my Swing application, as soon as I start the main() method, a dialog containing Username and Password fields with OK and Cancel buttons gets popped-up. I have a propertyChangeListener which gets notified when Ok or cancel is pressed and when Cancel is pressed, System.exit(0) is called to exit the JVM.
So, there are two threads running -
One - the main thread which invokes the dialog pop-up
Second - the propertychangelistener which calls the System.exit(0) on pressing Cancel button.
So, at times, after pressing cancel button, the application does not exit but invokes the previously running thread (main thread). But this does not happen always.
Could you please let me know why the application does not terminate completely and how to resolve this?
Thanks in advance!

Hi,
As I had already mentioned in my previous post -
Here is the pseudo-code which fails to terminate on pressing Cancel button at times.
================The Login dialog code=============
public LoginDialog()
// Other code
JOptionPane optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);
optionPane.addPropertyChangeListener(new PropertyChangeListener()
public void propertyChange(PropertyChangeEvent e)
          Object value = optionPane.getValue();
          if (value.equals(YES))
          else
// user closed dialog or clicked cancel
setVisible(false);
System.exit(0);
===============The main thread===================
This main() method calls the logindialog with username and passwrd as parameters.
So, initially, the main() thread is started and the login dialog is displayed. On pressing Cancel in this dialog, the control goes to propertyChangeListener of the loginDialog() and calls System.exit(0) which should terminate the entire application, but at times, the previously running main thread is resumed and the application is not terminated.
Please clarify why this happens.
Thanks in advance!!
});

Similar Messages

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

  • System.exit(0) closing both JFrames

    hey, ive got a problem with a JFrame
    Ive got 1 JFrame that currently holds a JMenuBar, 2 JMenus and in the 1st JMenu there are 4 JMenuItems.
    One of the JMenuItems uses an ActionListener to lauch another JFrame, but when the 2nd JFrame is finished (and System.exit(0) launches), the first JFrame closes as well. What is going on??
    code follows:
    THE MAIN JFRAME
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class realframe extends JFrame
    protected JMenuItem[] m_fontMenus;
    protected JCheckBoxMenuItem m_showPatList;
    protected JCheckBoxMenuItem m_showPatData;
    protected JCheckBoxMenuItem m_showHRGraph;
    protected JCheckBoxMenuItem m_showBPGraph;
    protected JCheckBoxMenuItem m_showTempGraph;
    public realframe(){
    super("PMS Menu GUI");
    setSize(450, 350);
    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);
    WindowListener wndCloser = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    addWindowListener(wndCloser);
    setVisible(true);
    //start Menus
    protected JMenuBar createMenuBar()
    final JMenuBar menuBar = new JMenuBar();
    //creates File
    JMenu mFile = new JMenu("File");
    //Menu 1 item 1 : : : Add Patient
    JMenuItem item = new JMenuItem("Add Patient");
    ActionListener lst = new ActionListener() //ActionListener for Add Patient
    public void actionPerformed(ActionEvent e)
    new realgui( new JFrame() );
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 2 : : : Delete Patient
    item = new JMenuItem("Delete Patient");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 3 : : : Search
    item = new JMenuItem("Search");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Divider
    mFile.addSeparator();
    //Menu 1 item 4 : : : Exit
    item = new JMenuItem("Exit");
    item.setMnemonic('x');
    lst = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    item.addActionListener(lst);
    mFile.add(item);
    menuBar.add(mFile);
    //end menu item 1
    ActionListener viewListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    updateMonitor();
    JMenu mView = new JMenu("View");
    mView.setMnemonic('V');
    //Menu 2 item 1 : : : Patient List Toggle
    m_showPatList = new JCheckBoxMenuItem("Patient List");
    m_showPatList.setMnemonic('L');
    m_showPatList.setSelected(true);
    m_showPatList.addActionListener(viewListener);
    mView.add(m_showPatList);
    //Menu 2 item 2 : : : Data box Toggle
    m_showPatData = new JCheckBoxMenuItem("Patient Data");
    m_showPatData.setMnemonic('D');
    m_showPatData.setSelected(true);
    m_showPatData.addActionListener(viewListener);
    mView.add(m_showPatData);
    //Divider
    mView.addSeparator();
    //Menu 2 item 3 : : : HR Graph toggle
    m_showHRGraph = new JCheckBoxMenuItem("Show HR Graph");
    m_showHRGraph.setMnemonic('H');
    m_showHRGraph.setSelected(true);
    m_showHRGraph.addActionListener(viewListener);
    mView.add(m_showHRGraph);
    //menu 2 item 4 : : : BP Graph Toggle
    m_showBPGraph = new JCheckBoxMenuItem("Show BP Graph");
    m_showBPGraph.setMnemonic('B');
    m_showBPGraph.setSelected(true);
    m_showBPGraph.addActionListener(viewListener);
    mView.add(m_showBPGraph);
    //menu 2 item 5 : : : Temp Graph Toggle
    m_showTempGraph = new JCheckBoxMenuItem("Show Temp Graph");
    m_showTempGraph.setMnemonic('T');
    m_showTempGraph.setSelected(true);
    m_showTempGraph.addActionListener(viewListener);
    mView.add(m_showTempGraph);
    menuBar.add(mView); //adds the menu
    return menuBar;
    protected void updateMonitor() { }
    public static void main(String argv[]) { new realframe(); }
    THE SECONDARY JFRAME
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class realgui extends JDialog implements ActionListener
    JTextField surname;
    JTextField given;
    JTextField age;
    JTextField doctor;
    JTextField phone;
    Patient patient = new Patient();
    JRadioButton radiomale;
    JRadioButton radiofemale;
    public realgui( JFrame frame )
    super( frame, true );
    System.out.println("in 1");
    setTitle( "Add A New Patient" );
    setSize( 400, 250 );
    JPanel panel = new JPanel( new BorderLayout() );
    panel.setLayout( new GridBagLayout() );
    panel.setBorder( new EmptyBorder( new Insets( 5, 5, 5, 5 ) ) );
    getContentPane().add( BorderLayout.CENTER, panel );
    GridBagConstraints c = new GridBagConstraints();
    Dimension shortField = new Dimension( 40, 20 );
    Dimension mediumField = new Dimension( 100, 20 );
    Dimension longField = new Dimension( 180, 20 );
    EmptyBorder border = new EmptyBorder( new Insets( 0, 0, 0, 10 ) );
    EmptyBorder border1 = new EmptyBorder( new Insets( 0, 20, 0, 10 ) );
    c.insets = new Insets( 2, 2, 2, 2 );
    c.anchor = GridBagConstraints.WEST;
    JLabel lbl1 = new JLabel( "Surname:" );
    lbl1.setBorder( border );
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    panel.add( lbl1, c );
    surname = new JTextField();
    surname.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(surname, c );
    JLabel lbl7 = new JLabel( "Given Name:" );
    lbl7.setBorder( border );
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    panel.add( lbl7, c );
    given = new JTextField();
    given.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(given, c );
    JLabel lbl2 = new JLabel( "Age:" );
    lbl2.setBorder( border );
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    panel.add( lbl2, c );
    age = new JTextField();
    age.setPreferredSize( shortField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( age, c );
    JLabel lbl3 = new JLabel( "Gender:" );
    lbl3.setBorder( border );
    c.gridx = 0;
    c.gridy = 3;
    panel.add( lbl3, c );
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout( new FlowLayout( FlowLayout.LEFT, 5, 0 ) );
    ButtonGroup group = new ButtonGroup();
    radiomale = new JRadioButton( "Male" );
    radiomale.setSelected( true );
    group.add(radiomale);
    radiofemale = new JRadioButton( "Female" );
    group.add(radiofemale);
    radioPanel.add(radiomale);
    radioPanel.add(radiofemale);
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( radioPanel, c);
    JLabel lbl4 = new JLabel( "Doctor:" );
    lbl4.setBorder( border );
    c.gridx = 0;
    c.gridy = 4;
    panel.add( lbl4, c );
    doctor = new JTextField();
    doctor.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(doctor, c );
    JLabel lbl5 = new JLabel( "Phone Number:" );
    lbl5.setBorder( border );
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 1;
    panel.add( lbl5, c );
    phone = new JTextField();
    phone.setPreferredSize( mediumField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(phone, c );
    JButton submitBtn = new JButton( "Submit" );
    c.gridx = 4;
    c.gridy = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    panel.add( submitBtn, c );
    submitBtn.addActionListener(this);
    JButton cancelBtn = new JButton( "Cancel" );
    c.gridy = 1;
    c.anchor = GridBagConstraints.NORTH; // anchor north
    panel.add( cancelBtn, c );
    cancelBtn.addActionListener(this);
    WindowListener wndCloser = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    addWindowListener( wndCloser );
    setVisible( true );
    public static void main( String[] args ) {
    new realgui( new JFrame() );
    public void actionPerformed(ActionEvent evt)
    if (evt.getActionCommand ().equals ("Submit"))
    Person person = new Person();
    String surnam = surname.getText();
    String give = given.getText();
    String ag = age.getText();
    String docto = doctor.getText();
    String phon = phone.getText();
    char gende;
    if(radiomale.isSelected()==true)
    gende = 'M';
    else
    gende = 'F';
    System.out.println("in 2 " + surnam);
    person.setSurname(surnam);
    person.setGiven(give);
    // person.setAge(ag);
    person.setDoctor(docto);
    person.setPhone(phon);
    person.setGender(gende);
    System.out.println(surnam + " " + give + " " + ag + " " + gende + " " + docto + " " + phon);
    person.setHistory();
    patient.add(person);
    System.exit(0);

    No, dispose() is inherited. Just replace System.exit(0); with:
    setVisible(false);
    dispose();I think that'll work in your code.

  • System.exit(0); reboots PC..........

    Hello all,
    I compiled and ran this program with no problems about 5 or 6 times as soon as I finished writing it. I walked away for about 15 minutes and tryed to run it again. The program runs fine up until the end; now, however, at the System.exit(0); line the system promptly REBOOTS.
    I am running windows XP Pro.....
    Any ideas as to what may be causing this?
    1. Take input from user for how many numbers will be in the array.
    2. Allow user to input the values 0ne by one usig for loop and break loop upon reaching
    value input from number 1(above).
    3. Make class to do linear search
    import javax.swing.JOptionPane;
    public class LinearSearch
      public static void main(String args[]) {
    SearchArrayLinear X = new SearchArrayLinear();
        String input, input2, input3;
        int array[], len, element, key;
        input = JOptionPane.showInputDialog(null,
            "How many integers do you want to input into the array? ", "INPUT",
            JOptionPane.QUESTION_MESSAGE);
        len = Integer.parseInt(input);
        array = new int[len];
        for (int counter = 0; counter < len; counter++)
        array[ counter ] = Integer.parseInt( JOptionPane.showInputDialog(null,
                                      "Input index " + counter + " into the array",
                                      "INPUT", JOptionPane.QUESTION_MESSAGE) );
       X.linearSearch(array);
    class SearchArrayLinear
    public void linearSearch( int array2[] ) {
        String input = JOptionPane.showInputDialog(null, "Enter the Search key ",
                                             "Search Key Input",
                                             JOptionPane.QUESTION_MESSAGE);
        int key = Integer.parseInt(input);
    for( int counter = 0; counter < array2.length; counter++)
          if (array2[counter] == key) {
            JOptionPane.showMessageDialog(null,
                                          "The search key was found in element " +
                                          array2[counter], "RESULT",
                                          JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
          else {
            JOptionPane.showMessageDialog(null,
                " No element was found for the search key ",
                "RESULT",
                JOptionPane.INFORMATION_MESSAGE);
            System.exit(0);
    }

    Get this. Microsoft says that this is a "Driver problem" and to check the latest installed driver. At first, I didn't think much of it because I havn't installed any drivers or hardware between the time it was working and the time it quit working....or so I thought.
    Apparently, one of the Microsoft automatic updates was a new processor driver for XP Pro. Since then, I cannot run any java programs without using JBuilder8. If I do, the computer reboots whenever the program reads the System.exit(*); line.
    Looks like Microsoft has found yet another way to sabotage java.
    Go figure.

  • Constructor    -    open new Window     -    System.exit(0)

    I have 1 package, with 2 java files, lets say a.java and b.java, both are compiled.
    a.java and b.java are frontends.
    Program starts with "a.java". Here I have a button for "b.java".
    If I want to call b.java in a.java, then I call the constructor of b in a.
    Then, if b is visible (and clickable), a is in background and is not clickable, until I cancel b.
    I would like to do 2 things :
    1) If I call b from a, it should be independant, so I still want to have access to a.
    2) If I call b from a, and use System.exit(0) in b. I want, that only b exits, and not both b and a.
    thanks,
    Aykut

    For the second requirement, the only thing you can do is to have a.class and b.class run in a seperated JVM. This also satisfy the first requirement.
    But for the first requirement alone, I leave to the Swing/AWT expert to answer you.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Keep external process alive after System.exit(0)

    I wish to start Outlook from my Java program and have my own program exit normally but keep alive the Outlook process. Besides, I am not interested in input/output/error streams.
    public class OutlookStarter {
         public static void main(String[] args) throws Exception {
              new ProcessBuilder("cmd", "/c",
                        "\"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();
    }When I run this when Outlook is not started, my program will not exit until I close Outlook.
    I really do not want to close Outlook just to exit my program (my real program has a Swing GUI and users must be able to close it).
    Also when I run this when Outlook is already started, somehow my program DOES exit without closing the new Outlook window.
    EDIT: I can add System.exit(0) and behavior is the same. I can use Runtime.getRuntime().exec and behavior is the same.
    Edited by: Strider80 on Jan 12, 2011 7:27 AM

    Strider80 wrote:
    I wish to start Outlook from my Java program and have my own program exit normally but keep alive the Outlook process. Besides, I am not interested in input/output/error streams.
    public class OutlookStarter {
         public static void main(String[] args) throws Exception {
              new ProcessBuilder("cmd", "/c",
                        "\"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();
    Did you try using [url http://www.computerhope.com/starthlp.htm]start ^[url http://www.computerhope.com/starthlp.htm]Microsoft DOS and command prompt^ ?
              new ProcessBuilder("cmd", "/c",
                        "start \"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();

  • System.exit

    Before user is about to close the gui, I want to free up the open sockets used in my application. Now, we don't want to poll the exit, waiting for the open sockets to finally free themselves and than the application quits. The user is going to thing something is wrong with the application and wonder why its taking to long to exit :)
    So, I thought of putting the close sockets in a thread and start it,
    but the next line after the start thread code in the main thread code
    is System.exit. Now once that calls, the free sockets thread
    won't do any work on closing the sockets, because the JVM is realease from its resource. Now I'am damm if don't use a thread or damm if using a thread (Not doing anything).
    Can I have a Thread as another JVM to free the sockets while the application exit?
    Thanks

    Please don't crosspostimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test() {
         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         Container content = getContentPane();
         JButton jb = new JButton("Exit");
         content.add(jb,BorderLayout.SOUTH);
         jb.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae) {
              doFinalStuff();
         addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent we) {
              doFinalStuff();
         setSize(200,200);
         show();
        private void doFinalStuff() {
         dispose();
         for (int i=0; i<10; i++) {
             try { Thread.sleep(1000); } catch (Exception exc) {}
             System.out.println(i);
         System.exit(0);
        public static void main(String[] args) { new Test(); }
    }

  • How to intercept "System.exit"?

    I am writing a large GUI application that optionally spawns other GUI threads. These spawned threads are special-purpose text editors. It is important that the editor knows when it is about to be closed, so that it can prompt the user to save a modified file.
    The editors are based upon javax.swing.JFrame, and I have overridden the "windowClosing" method of a WindowAdapter to check file status and prompt when necessary. This method performs as desired when I close the editor window manually. However, when I close the main application (which calls System.exit(0) ), the editor frames also close without any invocation of my windowClosing method.
    Is there any way the dependent editor JFrame can be alerted that the virtual machine is about to be ended? I could probably keep a list in my main application of all the dependent processes that need to be cleanly ended, but it would be much simpler (and so much more object-oriented) if the dependent thread could take care of itself!

    MarkHausman wrote:
    As you suggested, I posted this question on the Swing forum.
    For those who are interested: the Swing solution I was offered was to make use of the static function Frame.getFrames(). This allows access to all frames launched by an application. By putting this call in my main shutdown method, I can identify all spawned editor frames and call each one's shutdown method.
    This is not as satisfying as my original desire, to have the spawned frame recognize when the VM is about to close, but it is easy enough to implement that I am going with it.And why wouldn't addShutdownHook() work?

  • Can I intercept "System.exit" in a spawned GUI thread?

    I am writing a large GUI application that optionally spawns other GUI threads. These spawned threads are special-purpose text editors. It is important that the editor knows when it is about to be closed, so that it can prompt the user to save a modified file.
    The editors are based upon javax.swing.JFrame, and I have overridden the "windowClosing" method of a WindowAdapter to check file status and prompt when necessary. This method performs as desired when I close the editor window manually. However, when I close the main application (which calls System.exit(0) ), the editor frames also close without any invocation of my windowClosing method.
    Is there any way the dependent editor JFrame can be alerted that the virtual machine is about to be ended? I could probably keep a list in my main application of all the dependent processes that need to be cleanly ended, but it would be much simpler (and so much more object-oriented) if the dependent thread could take care of itself!

    I was not aware of the Frame.getFrames() method; this is apparently good enough to find all the dependent windows I have created. Thanks for pointing this out.
    As to the spawned threads, perhaps you could comment on my method. I was actually hoping to open the editors as independent applications that would persist after the main GUI was closed. To do this, I gave my editor class an associated static Runnable, like so:
       public static class Starter extends Thread {
             String[] arguments = new String[0];
             public void run() {
                MyEditor re = new MyEditor();
                if( arguments.length > 0) re.setFileName(arguments[0]);
                re.setVisible(true);
             public void copyArguments( String[] args) {
                arguments = Arrays.copyOf(args, args.length);
       }which I invoked from my main GUI in the following code:
       Starter starter = new Starter();
       String[] startArgs = {"myfilename.txt", "more parameters"};
       starter.copyArguments(startArgs);
       starter.setDaemon(false);
       starter.start();This does indeed start the editor, but it is in the same virtual machine, since the editor stops when the GUI stops. Is this method setting me up for trouble? Is there a way to do what I originally wanted, starting the editor in a new virtual machine?

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

  • Dispose() / system.exit()

    which one is good to close an application ?
    dispose()
    OR
    system.exit()

    I'm not certain how the above discussion relates to
    swing apps - (been a long time since I messed with
    swing). I have a vague recollection that in swing,
    you have to terminate the VM in order to get the GUI
    threads to stop - but that was a long time ago, and
    may no longer be the case...That's true, sorta. I believe that in Java 1.4, this was fixed, so if the last window is disposed, the app will end (as long as there's no other non-daemon threads running that the app started). The event thread won't hold it up, at least.
    So if you don't know what environment your app will run in, it's safes to use System.exit() to quit a UI app.
    The general rule is you should use dispose() to close the windows if they aren't needed anymore. Then for UI apps if it's really quitting time, use System.exit(), unless you know that the app is running in a Java version that doesn't need it.
    System.exit() can also be used if you want to exit the app now regardless, but it's considered bad form to not let threads terminate on their own. But I suppose sometimes you just have to exit.

  • Why in COM, set smth true, stays true even after System.exit?

    I am using "Jacob" to do COM calls. When I alter the "ShowAll" property of Word.Application and I set it to true, it will then forever be true even if I exit the application AND quit the word application. If I set it to false, the same thing happens, it will always be so. The code to call/set this is:
    (NOTE: This uses classes I made to wrap the Dispatch calls)
    Word wordApp = new Word();
    Documents docs = wordApp.getDocuments();
    Document doc = docs.open("D:\\JavaProjects\\Test.doc");
    //GET VIEW
    View wordView = wordApp.getActiveWindow().getView();
    //PRINT THE VIEW PROPERTIES
    System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
    System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
    //SET THE VIEW PROPERTIES
    wordView.setShowAll(false);
    wordView.setShowParagraphs(true);
    //PRINT THEM AGAIN
    System.out.println("Show All: " + wordApp.getActiveWindow().getView().isShowAll());
    System.out.println("Show Paragraphs: " + wordApp.getActiveWindow().getView().isShowParagraphs());
    doc.close(Document.DO_NOT_SAVE);
    wordApp.quit(new Variant[] {});
    System.exit(0);The actual Dispatch calls are:
    //NO IDEA WHY THIS IS, BUT SHOWALL = TRUE IS -1, AND FALSE IS 0
    private final static int SHOW_ALL_TRUE = -1;
    private final static int SHOW_ALL_FALSE = 0;
    /** SETSHOWPARAGRAPHS **
    * Sets the property (boolean) ShowParagraphs.
    public void setShowParagraphs(boolean showParagraphs)
         Dispatch.put(this, "ShowParagraphs", new Boolean(showParagraphs));
    /** ISSHOWPARAGRAPHS **
    * Returns Boolean of whether or not this is set to show paragraphs.
    public boolean isShowParagraphs()
         return getBooleanValue(Dispatch.get(this, "ShowParagraphs"));
    private boolean getBooleanValue(Variant variantBoolean)
         //MAKE IT AN INTEGER AND GET ITS int VALUE
         int intVariant = new Integer(variantBoolean.toString()).intValue();
         //RETURN IF IS SHOW ALL
         return (intVariant == View.SHOW_ALL_TRUE);
    }I'm wondering if the problem is that I get back either -1 or 0 and if maybe that means something else?

    1: Properties persistence is not a DEFECT but a FEATURE . It was implemented in MS Word so users could change MS word WITHOUT HAVING TO DO IT EACH TIME THEY START IT UP.
    2: Don't you intialise all your variables in your code after you instanciated them ? I am sure you do so and therefore the persitence feature you described should not be annoying you at all. It is not necessary to intialise variables in the BASIC langage but that does not mean you should not do it.
    3: (-1) was chosen arbitrary by Microsoft as the TRUE value for Boolean datatype and 0 the value for FALSE when they designed Visual Basic. This is not a problem if you write code properly
    I recommend you test bool variable in any langages using the following test:
    (myBool <> 0)
    HAVE A THINK ABOUT IT
    Finally,
    you need to understand what you are working with before you complain about it.
    Argument for Argument sake is not good and if you think MS word is a bad program just don't use it. go and write your own word processor in JAVA.
    GOOD LUCK
    I WISH TO APOLOGISE FOR ANY POSSIBLE SPELLING OR GRAMMATICAL MISTAKES I COULD HAVE MADE IN THIS REPLY. ENGLISH NOT BEING MY FIRST LANGUAGE.

  • Denying system.exit in java code

    My objective is to nullifying the system.exit programmed. By goggling i learn t that this can be done by adding permission in policy file. But as far my google search i dont understand how to deny a permission. Most of them says about granting a permission. Can anyone clarify how to deny a permission.
    Steps i tried.
    Sample program: which does nothing other than calling system.exit(0) as the first line in main method.
    added the following line to java.policy file in my JAVA_HOME/jre/lib/security
    grant {
              permission java.lang.RuntimePermission "exitVM";
    Also tried adding only
    permission java.lang.RuntimePermission "exitVM";
    to the already available grant block.
    Also commented out
    //grant codeBase "file:${java.home}/lib/ext/*" {
    //     permission java.security.AllPermission;
    After that i understood that the default java policy file is java.home\lib\security\java.policy. So made all the change above mentioned there too.
    But i could not achieve it. Can any one help me on this.
    Win 2000/ Java1.4.2_12/no command line arguments while running the program.

    Welcome to the Forums.
    Please go through the FAQ of the Forum.
    You has posted your query in the wrong Forum, this one is dedicated to Oracle Forms.
    Please try {forum:id=1050}.
    Regards,

  • The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL

    Hi
    We are using SRM 5.0. We are facing a strange problem. We are able to see the initial screen of SRM EBP in the browser. But once the user name and password are provided the system goes for a dump with the following error:
    The following error text was processed in the system SS0 : System error
    The error occurred on the application server <Server Name> and in the work process 0 .
    The termination type was: ABORT_MESSAGE_STATE
    The ABAP call stack was: SYSTEM-EXIT of program BBPGLOBAL
    <b>SM21 Log:</b>
    Short Text
         Transaction Canceled &9&9&5 ( &a &b &c &d &e &f &g &h &i )
         The transaction has been terminated.  This may be caused by a
         termination message from the application (MESSAGE Axxx) or by an error
         detected by the SAP System due to which it makes no sense to proceed
         with the transaction.  The actual reason for the termination is
         indicated by the T100 message and the parameters.
    Transaction Canceled ITS_P 001 ( )
    Message Id: ITS_P
    Message No: 001
    I just checked these threads but did not help much,
    RABAX_STATE  error after loggin into BBPSTART service in SRM 4.
    ITS_TEMPLATE_NOT_FOUND error
    Besides I tried this note: 790727 as well, still I get the same error.
    Any help would be highly appreciated.
    Thanks in advance
    Kathirvel Balakrishnan

    Hi
    <u>Please do the following steps.</u>
    <b>When you are using the Internal ITS,you need not run the report W3_PUBLISH_SERVICES.(only SIAC_PUBLISH_ALL_INT )
    ALso pls check the foll:
    -->activate the services through SICF tcode.
    > Go to SICF transaction and activate the whole tree under the node Default host>sap>bc>gui>sap>its.
    >Also maintain the settings in SE80>utilities>settings>internet transaction server-->test service/Publish. (BBPSTART , BBPGLOBAL etc)
    Table TWPURLSVR should have entries for the / SRM server line as well as gui and web server.
    Could you please review again the following steps ?
    Did you check that ICM was working correctly (Transaction -  SMICM) ?
    1-Activate the necessary ICF services
    With transaction SICF and locate the
    services by path
    /sap/public/bc/its/mimes
    /sap/bc/gui/sap/its/webgui
    2- Publish the IAC Services
    With Transaction SE80 locate from
    the menu Utilities -> Settings ->
    Internet Transaction Server (Tab) ->
    Publish (Tab) and set “On Selected
    Site” = INTERNAL.
    3- Locate the Internet Services SYSTEM and WEBGUI.
    Publish these services with the Context
    Menu -> Publish -> Complete Service
    4- Browse to http://<server>:<icmport>/sap/bc/gui/
    sap/its/webgui/! and login to the
    webgui.</b>
    Hope this will help.
    Please reward suitable points.
    Regards
    - Atul

  • How  to track System.exit(0) call

    hi there,
    how can i trace the System.exit(0) function call in my program.
    i.e as we know which class is being loaded into the jvm by overriding
    the classloader, can we similarly know when is our jvm going to be
    destroyed. here iam invoking jvm from my windows program using invocation api.
    any help is mostly appreciated.
    thanks in advance
    bye
    ramana

    Not sure I know what you are asking.
    You could create a security manager which prevents exit() from being called.
    You could replace System using the bootstrap command line option. Although if you do that you can not distribute it due to the license agreement. Once replaced you can do anything you want in the application.
    You could use Runtime.addShutdownHook() if you just want to do something when the application exits.

Maybe you are looking for