Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java code to clear screen?

Options
  • 30-05-2007 10:42pm
    #1
    Closed Accounts Posts: 5,240 ✭✭✭


    Anyone know any simple code that can clear the screen at a certain stage, all i could think to do was setup a loop with a load of System.out.println(""); statements which would loop until the screen was clear?

    Cheers
    Endo


Comments

  • Registered Users Posts: 43,916 ✭✭✭✭Basq


    Depends on the OS... on Windows 9x and Unix, you can use:

    System.out.println(((char) 27)+"[2J"); // ANSI clear screen...

    But NOTHING works in Windows NT. So you can use your method above for NT as that's the best bet.

    Hope this helps!


  • Closed Accounts Posts: 5,240 ✭✭✭Endurance Man


    basquille wrote:
    Depends on the OS... on Windows 9x and Unix, you can use:

    System.out.println(((char) 27)+"[2J"); // ANSI clear screen...

    But NOTHING works in Windows NT. So you can use your method above for NT as that's the best bet.

    Hope this helps!

    Ye figured that much, asked my programming lecturer and she didnt even have an answer, will have to stick with the ol loop.


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    how about this
    String clearScreenCommand = null;
    if( System.getProperty( "os.name" ).startsWith( "Window" ) )
       clearScreenCommand = "cls";
    else
       clearScreenCommand = "clear";
    
    Runtime.getRuntime().exec( clearScreenCommand );
    

    checks if it's running windows and all :p


Advertisement