0

// It is horse racing and the loop is looping the horses position a little further each time it loops. Without clearing the screen it just shows the previous position before each new position and it looks sloppy. I am trying to clear the old positions before running the new positions

braX
  • 11,506
  • 5
  • 20
  • 33
  • 1
    It sounds like you are using the console...if so, take a look at this: http://stackoverflow.com/questions/2979383/java-clear-the-console – Nathan Merrill Nov 27 '13 at 22:32
  • If you're on Unix, you might also want to check out [ANSI escape codes as mentioned here](http://stackoverflow.com/q/10241217/56285). Or then just go with a [good Java library for console apps](http://stackoverflow.com/q/439799/56285). – Jonik Nov 27 '13 at 22:51

2 Answers2

3

It depends on which OS you are:

  • On windows, you can clear using: Runtime.getRuntime().exec("cls" );
  • On Unix: Runtime.getRuntime().exec("clear")
T0to
  • 422
  • 2
  • 5
2

If you are using console. You can execute cls or clear commands from your code by doing as follows. This is system dependent.

  Runtime.getRuntime().exec("cls"); //Windows
  Runtime.getRuntime().exec("clear"); //Linux
Vallabh Patade
  • 4,960
  • 6
  • 31
  • 40