How to Exit Java Window after a command in Blue-J?

Here I use System.exit(0); to exit the program. But using this just minimizes the window. Is there any way to close the window. P.S - This is just a class which links to Main_Menu Class if the entered value is 1. This is not the full code! Quadratic Equations - BlueJ Program - Image Thank You

asked Jul 15, 2017 at 4:21 Abhinav S Thakur Abhinav S Thakur 1 1 1 silver badge 3 3 bronze badges

1 Answer 1

The call to System.exit(0) just terminates the currently running Java Virtual Machine. It doesn't necessarily close the terminal window. A Java program does not know anything about it's context, so it cannot access the window it is using for its output.

However, there are two different ways to clear the terminal in BlueJ. You can get BlueJ to automatically clear the terminal before every interactive method call. To do this, activate the 'Clear screen at method call' option in the 'Options' menu of the terminal. You can also clear the terminal programmatically from within your program. Printing a formfeed character (unicode 000C) clears the BlueJ terminal, for example:

System.out.print('\u000C'); 

This will work in the BlueJ terminal, but is not guaranteed to have the same effect in all terminals. You could, for example, create a method with this in it and call that method whenever you want to clear the terminal screen.

public void clearScreen()