DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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 09: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, 05:54 PM
  2. Comparison methods
    By ericelysia1 in forum Java
    Replies: 34
    Last Post: 05-15-2005, 06:39 PM
  3. System.exit(0) not working :(
    By Lim Wing Hoe in forum Java
    Replies: 4
    Last Post: 10-27-2000, 12:48 AM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links