1

I try to clear the console window and continue execute the rest of my code(like you navigate to another page when browse web pages)

I found Runtime.getRuntime().exec("cls"); but it doesn't work,and says can not run program cls

and I also found a suggestion like print thousand empty lines, which is not what i want. I would like to have something like

 old code goes here....
 showOption(); //this would display three option like 1,2,3
 input=userInput.nextInt();
 if(input==1){
   clearWindow();/clear the previous stuff from the console
   showOptionOneDetail(); //leave only option one detail on the console
 }

after the user select a option, like 1, then i want to clear window, and continue display the detail for the specific option, it's that possible?

I'm testing using mac in eclipse

Kesong Xie
  • 1,316
  • 3
  • 15
  • 35

1 Answers1

0

Dear friend: You are trying to develop a Rich User Interface over a text console, which is a bad environment choose. I'd recommend that you'd better use Java Swing for that, which requires more programming effort, but it also turns out in a better user experience.

BUT, if you ABSOLUTELY need to re-paint your user "screens" in a text-only environment, I doubt that executing system commands (like "cls") would be useful here. The only choice I think you MIGHT have is to output the BACKSPACE character (ascii 8) as many times as characters have been printed to the console last time, and then produce the new "screen". I've never tried that in Eclipse, sou you'll have to give it a try. Good luck!

Little Santi
  • 8,563
  • 2
  • 18
  • 46