Exit the system in java

Associate
Joined
6 Mar 2009
Posts
495
As part of an assignment i have to created a menu drivin system with different things that the user can do. For example, read info and then take quizes on that info.

Im am looking for a piece of code that will exit the system the system when the user has finished. What way would you put it into a method??

Im relatively new to java so could you take it step by step. Im am using Eclipse btw.

Thanks
 
You mean to quit the program when they have finished?

Why not just have them close the program using the 'x' button on the top right of the app (I am assuming this is GUI and you have implemented standard buttons). Then it's a simple System.exit(0); in the event for that button.

Not fancy but I guess it would do the job.
 
If it's a simple menu + input loop -> just break the loop and let main() complete. Your program will terminate on it's own once there are no more user threads running.

System.exit() is required if you have additional user threads running that you don't want to wait for or can't clean up, like all the Swing-related threads that get started if you touch any GUI stuff in your program.
 
I have to do a GUI version and a console version. Have got the GUI one working by creating an exit button that exits the system when click on. But not sure how to do it through the console, by using a method. Also how could you return to the previous screen by using methods?

Thanks
 
Back
Top Bottom