Results 1 to 6 of 6

Thread: Java code to quit an application

  1. #1
    Join Date
    Dec 2009
    Posts
    178

    Java code to quit an application

    Hello,
    I created a small menu composed as follows:
    1. Create a list of integer (in a txt file)
    2. Add an integer
    3. Add up all these numbers
    4. Exit
    I know how I can do to quit the application by selecting option 4.
    Have you any idea about this? Thanks for the help

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: Java code to quit an application

    Hello,
    I think you should try the following code, if I am not wring then this should work.
    Code:
    System.exit(0);
    If it is a graphical interface with buttons, it is necessary that you put the System.exit (0) in the actionPerformed method in your ActionListener. Hope the information will help you.

  3. #3
    Join Date
    Nov 2009
    Posts
    333

    Re: Java code to quit an application

    Hello,
    The System.exit (0) is a classic and completely ends the JVM, by cons, a normal end of the program is instead leaving all the thread terminates normally. In console mode, you must have one main thread that is the one who started the hand, and you must also have a loop that asks for the menu, you must exit this loop and let go the main thread after execution, and ends without any exit(0). I guess you get the thing properly what i am trying to explain you here.

  4. #4
    Join Date
    Dec 2009
    Posts
    213

    Re: Java code to quit an application

    Hello,
    Even I was trying the same part of the code, but I have found a solution for this yet.
    I have also tried the following code
    Code:
    System.exit(0);
    and it works very well. Can I, by curiosity, you wonder why we put 0 in brackets?
    exit () is a function and I assume the 0 is there any argument? Otherwise, you can put the arguments? Thank you for your help.

  5. #5
    Join Date
    Nov 2009
    Posts
    583

    Re: Java code to quit an application

    Hello,
    No, 0 is an error code. By convention program returns 0 if everything goes well and 1 or more when an error has occurred which causes the program has ended. It is very useful when a program calls another to determine if the execution was properly placed (Solicitation when programming a lot in a batch / bash / etc .. but also in environmental graphics). In C / C + + is often defined in the constants or macros EXIT_SUCCESS (which corresponds to 0) and EXIT_FAILURE (which corresponds to 1). Strangely in Java he did nothing of the sort defined even if a program is ending properly sense returns 0.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Java code to quit an application

    Hello,
    I agree with the above post and would like to add a few words. For error codes themselves, if your program has, you can define them as you like but there is a list of POSIX code presets that are relatively standardized on most platforms for errors currents (not possible ' open a file, not possible to read a file, specify the file is actually a directory, socket error, etc. ...). It is also possible that there are error codes own a standard Windows or other OS but I do not know.

Similar Threads

  1. How to quit the Pandora application on Motorola Xoom 2?
    By ashwin2012 in forum Portable Devices
    Replies: 5
    Last Post: 12-01-2012, 12:37 PM
  2. help me to understand java code (calendar java code) ?
    By so0oma in forum Software Development
    Replies: 2
    Last Post: 10-01-2011, 12:01 AM
  3. How to force quit application
    By Sandroo in forum Operating Systems
    Replies: 5
    Last Post: 06-02-2010, 11:56 AM
  4. Help with java application
    By gec5741 in forum Software Development
    Replies: 1
    Last Post: 29-12-2009, 04:32 PM
  5. Error : "the application adobe flash has unexpectedly quit"
    By geokilla in forum Windows Software
    Replies: 3
    Last Post: 17-11-2009, 01:16 PM

Tags for this Thread

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
  •  
Page generated in 1,713,540,328.04128 seconds with 17 queries