1

I'm practicing basic programming in Java on BlueJ and doing a personal project in which the program will print characters in '*' form each 5 lines long based on the input.
I was wondering if there is way to go back to a specific line in the terminal window of BlueJ or do I have to work some other way?

If someone can give any suggestions to simplify the program, it would be helpful.

SantiBailors
  • 1,596
  • 3
  • 21
  • 44
sphd
  • 25
  • 3
  • http://stackoverflow.com/questions/9693124/override-previous-console-output One line kind of works, multiple no. – Adrian Leonhard Apr 05 '15 at 10:55
  • You have to [clear the console](http://stackoverflow.com/questions/1682212/clear-screen-option-in-java?lq=1) and print again. – Gabriel Negut Apr 05 '15 at 10:57
  • So basically no possible way to jump to previous line after printing multiple lines?@AdrianLeonhard @GabrielNegut – sphd Apr 05 '15 at 11:43
  • Technically speaking, you could do it by some native platform-specific code, but that's too complicated for your use case. Write a bunch of newlines to clear the console, reprint and that's it. – Gabriel Negut Apr 05 '15 at 11:48

1 Answers1

0

An OS-independent, device-independent, general way of doing it is to make a two dimensional character array which represents the screen. Being an array, you can of course fill it up in any order. Once ready, A simple nested loop can print out the contents to the output stream. Also language-independent.

Possible problems of this approach include output worth several thousand lines, or lines too wide.

Abhay
  • 768
  • 4
  • 13
  • But there is no way of knowing the screen size without resorting to OS specific code, so you can only make the array "big enough" and hope you don't write outside the bounds of the actual screen. – Gabriel Negut Apr 05 '15 at 13:56
  • @GabrielNegut Right! That's what I wanted to say in the last line. So one solution is to use some minimal system dependent code to find out screen size, and pass it to our "rendering" method. When porting, only the wrapper needs to change. – Abhay Apr 05 '15 at 13:59
  • @Abhay, Thank you, that seems to be a an approach that could work out. I'll try it out. – sphd Apr 05 '15 at 16:33