System.exit(0);


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: System.exit(0);

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    59

    System.exit(0);

    I'm a bit new to java programming and I wanted to make my application close when I click on a JMenuItem (named Exit). The code behind it is partly generated with NetBeans GUI builder.

    Code:
    Exit.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    CloseWindow(evt);
                }
            });
    And the CloseWindow(evt) code

    Code:
    private void CloseWindow(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
        System.exit(0); 
    }
    But for some reason, the app won't close when I click the menu item.

  2. #2
    Join Date
    May 2007
    Posts
    59
    Doesn't anybody know why my exit button doesn't work?

    EDIT - Ok found it. For some reason I can use a JMenu instance to make events occur, but a JMenuItem event doesn't do anything. Can anybody explain that to me?
    Last edited by Armaron; 04-09-2009 at 10:17 AM.

  3. #3
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    I think you have to use addActionListener() in the menuItem. A menu item may not only be fired through mouse clicks, people may also use the keyboard to use a menu, or a menu 'hot key' to directly acces the menu item. So, to provide maximum usability, you should always use the actionListener for default actions, like selecting a menu item, clicking on a button / checkbox, etc.

Similar Threads

  1. Help some one please
    By jose in forum Java
    Replies: 4
    Last Post: 09-17-2005, 06:54 PM
  2. Comparison methods
    By ericelysia1 in forum Java
    Replies: 34
    Last Post: 05-15-2005, 07:39 PM
  3. System.exit(0) not working :(
    By Lim Wing Hoe in forum Java
    Replies: 4
    Last Post: 10-27-2000, 01:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center