Clearing the terminal

A frequently asked question is whether you can automatically clear the terminal in BlueJ. There are, in fact, two different ways.

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, like this:

private void clearScreen()
{
System.out.print('\u000C');
}
This is specific to the BlueJ terminal (and maybe some other terminals, but clearly not all).

While it may be useful to use this, it is also a good place to discuss OS specific behaviour (and why to avoid it). Different terminals react differently to control codes (that is: printing of characters with ASCII values below 0x20). Some terminals may honour things like backspace, bell, formfeed, others may not. Everyone honours CR and LF in some form, but that's almost all that's agreed on.

Source:bluej.org
Post a Comment

All Rights Reserved