Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   How do I clear the screen? (http://www.programmingforums.org/showthread.php?t=6212)

crawforddavid2006 Oct 1st, 2005 11:18 PM

How do I clear the screen?
 
How do I clear the screen when I restart the "game" with a loop?
:

import cs1.Keyboard;
import java.util.*;

public class HiLo
{
    public static void main (String[] args)
    {
        int play = 1;
        while(play > 0)
        {
        Random generator = new Random();
        int answer = generator.nextInt(100)+1;
       
        System.out.println("The computer is thinking of a number \nbetween 1 and 100. What is it?");
        int escape = 0;
        while(escape < 1)
        {
        int guess = Keyboard.readInt();
       
        if(guess == answer)
        {
            System.out.println("That's it");
            escape = 1;
        }
        else if(guess > answer)
        {
            System.out.println("Too High");
        }
        else if(guess < answer)
        {
            System.out.println("Too Low");
        }
        }
       
        System.out.println("Would you like to play again (y/n)");
        char again = Keyboard.readChar();
        if(again == 'y')
        {
            play = 1;
        }
        else if(again == 'n')
        {
            play--;
        }
    }
     
    }
}


Dameon Oct 1st, 2005 11:23 PM

Could try the escape code for clearing the screen

:

System.out.print ("\033c");

http://vt100.net/docs/vt102-ug/chapter5.html

Your mileage may vary.

crawforddavid2006 Oct 2nd, 2005 10:51 AM

Where would i put that?

Polyphemus_ Oct 2nd, 2005 11:47 AM

Quote:

Originally Posted by crawforddavid2006
Where would i put that?

where you want to clear the screen :)

if the code doesn't work, you can also print 30 newlines, that will also clear the screen.

Dameon Oct 2nd, 2005 12:30 PM

The code I gave you is an standard terminal escape code. It should work beautifully on everything *but* Windows. Microsoft's cmd is a terminal wannabe.

crawforddavid2006 Oct 2nd, 2005 6:48 PM

I need it to clear the screen if
:

again == y

Ooble Oct 3rd, 2005 4:20 PM

Then stick it in a while loop:
:

while (again == 'y')
{
    ...
}


crawforddavid2006 Oct 4th, 2005 5:40 PM

That did not work

tempest Oct 4th, 2005 5:48 PM

Show us what you tried...

Ooble Oct 4th, 2005 5:48 PM

Did you set again first?


All times are GMT -5. The time now is 2:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC