• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

periodically display diff string in the same position in the command console

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all:

in my program, i want to PERIODICALLY display some string in the SAME POSITION in the windows COMMAND CONSOLE.
certainly, it is easy to solve the "periodically" problem by using the Timer class, but what hamper me is how to display them in the SAME position within the windows command consle. so let us make the complex request simpler, consider following situation in your code:

System.out.print("hello world");
System.out.print("good morning");

the output may be following:

hello worldgood morning

but what i want is following:

1 display "hello world" in the console
2 delete "hello world" in the console
3 dispaly "good morning" in the original position of "hello world"?


who can help me?
thanks in advance!!
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just run the bellow code. Analyze the code and the output both.

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extension of Chetan Parekh example.


import java.util.Date;
public class Clock {
public static void main(String args[]) {
System.out.print(new Date());
while(true){
try{
Thread.sleep(1000);
System.out.print("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
System.out.print(new Date());
}catch(Exception e){
e.printStackTrace();

}
}
}
}
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the ASCII character for carriage return and you can just overwrite the previous output rather than printing a bunch of backspaces.

[ February 17, 2006: Message edited by: Joe Ess ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joe Ess you have maid a nice point.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Chetan. I learned that little trick here at the Java Ranch. It's amazing what you can pick up just hanging around.
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic