Clearing the screen using java

hi
how to clear the screen using a java program

for (int n = 0; n < 24; n++) System.out.println();
Even better: don't clear the screen. The program I ran before your program printed out very important things. If your program throws away those important things then I will not like you or your program.

Similar Messages

  • How to clear the screen in java?

    Hi,
    How to clear the screen in java without using any loops?
    Thanks

    Just paint with your background color to let the old paintings vanish.

  • Does anybody know how to Clear the screen in Java?

    Hi guys,In C we use System Clear.
    In java,which instructions shall i use in order to clear the screen?
    Thanks,in advance!

    Of course you shouldn't do so anyway...
    Terminal programs should coexist with all other terminal programs and not try to dominate the screen.
    They should never clear the screen as this would remove output from other programs running in the same terminal.

  • How i can clear the screen in JAVA?, in c++ is  command that called .......

    system("cls")
    but in JAVA??
    thx
    gicio1

    system("cls") is the silly way to do it. For a start, "cls" isn't on most computers, because most computers call it "clear". You could run this from Java using Runtime.exec("clear"), Runtime.exec("cls"), etc .. but the best way to clear the screen is still to print out N newlines, where N is the height of the screen.
    The only problem with this way is, you don't know the height of the screen. You could pass an environment variable in as a system property, from whatever launches your program, and if it's not there "assume" it's 200 or something. Then just build up a string with "\n\n\n\n\n\n\n\n"... and print it out. Blam, blank screen. :-)

  • How need to take screen shot of the screen using java.awt.Robot from javafx

    1) I am displaying a Stage which is having an image and shapes in it and wanted to take the screen shot as and when i move the shape( which moves the stage ).
    I am trying to java.awt.Robot, but i am getting headless exception. I used
    @Override
    public void start(final Stage primaryStage) {
    // creating some images and shapes
    Platform.runLater(new Runnable() {
    @Override
    public void run() {
    // update();
    public void update() {
    if (stg.isShowing()) {
    ScreenCapture.capture(stg.getX() + 2, stg.getY() + 2, (int) boundsOfCircle.getBoundsInParent().getWidth(), (int) boundsOfCircle.getBoundsInParent().getHeight());
    magnifierImageView.setImage(new Image(SCREEN_SHOT_FILE));
    public static void capture(final double x, final double y, final int width, final int height) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    System.out.println("x ="+x +" y = "+y +" width "+width +" height ="+height);
    Robot robot = new Robot();
    } catch (Exception e) {
    System.out.println("exception arised while taking the screen shot ");
    e.printStackTrace();
    The above code throws headless exception.
    2) The second issues is have a image & i am dividing the image into different rows and cols( images of same size ). This is i am doing using awt. and i wanted to load those different images into
    javafx images . I am facing the issues when i try to load the images into javafx.

    hi,
    click on print screen button in your keyboard.
    open a word document and do Ctrl V .
    *Reward points if it helped

  • How to clear the screen in the command prompt?

    Hello Everyone,
    I was wondering how we can clear the screen in the command prompt in Java. I remember we can do this in C by writing system("cls");
    What is the best IDE for writing Java programs. Is the NetBeans IDE good? Thank you very much.

    I was wondering how we can clear the screen in the
    command prompt in Java. I remember we can do this in
    C by writing system("cls");I guess there's no Java way of doing that because it's a function of the shell you're calling. If you try to use Runtime.exec on cls, it starts yet another shell, clears that, and closes it again, so it has no effect on your output.
    You could try using the '\b' backspace character, if that helps.
    What is the best IDE for writing Java programs. Is
    the NetBeans IDE good? Thank you very much.By the way you're asking this question, the answer will be almost certainly "none". If you want to, you can search this board for the few million times this question was asked before, pick all IDEs suggested there and use the one you're most comfortable with.

  • How to Clear the Console in java

    Hello
    i am new to java. in one of my assignment i have to clear the screen
    i have tried the following approaches which are not working , one more thing i am using win xp[ with service pack 2
    i have tried following
    1 passing th eansii escape sequence to output
    2 tried to use the Runtime class
    3 tried the Console class
    4 i want to avoid this system.out.println(" "); in a loop
    now what i have to do can anyone help me
    thanks

    Hello
    i am new to java. in one of my assignment i have to
    clear the screen
    have tried the following approaches which are not
    working , one more thing i am using win xp[ with
    service pack 2
    have tried following
    1 passing th eansii escape sequence to output
    2 tried to use the Runtime class
    3 tried the Console class
    4 i want to avoid this system.out.println(" "); in a loop
    now what i have to do can anyone help me
    thanksIf you want to do this with your standard command shell, the only practical solution would be option 4.
    Or have a look at JCurses, I believe it can do that kind of stuff:
    http://sourceforge.net/projects/javacurses/

  • Clearing the screen, and special characters

    First off, I want to be able to clear the screen between menu selections. I've been told it's hard, but I don't mind, and I DON'T want to just print a whole heap of lines...
    Second, How can I print special "High ASCII" characters, specifically the ones that are used in DOS borders around menus and windows. Unicode values from 2500 - 256C (Hex)
    Ta muchly,
    -Phil-

    It sounds like you want a CURSES library for java. This seems to be a rare thing since once people are willing to go to the effort of using curses, they just use AWT or Swing instead. But I've seen CURSES libraries out there. Try Google.
    If the DOS extended characters are really part of Unicode, then just print out the relevant characters. You can use Unicode escape sequences (\u0000) to do so. This assumes that the terminal can handle them, which it may not.
    You could just print out the terminal escape sequences to clear screen and position the cursor yourself, I suppose, but a CURSES library would probably be more portable.

  • Clearing the screen

    I realize this has probably been covered before but how do you clear the screen of previous lines of code?
    I am using Crimson Editor and the latest SDK and running programs in a DOS shell.
    Please let me know how to do it, if it is a DOS command how to implement into my program and if a java method what the parameters are.
    Thanks.

    If you are wanting to clear the DOS window, there is no provision in Java for that. You could output new lines from your program and force the data on the screed to scroll off.
    The DOS command to clear the screen is "cls" and you will need to use runtime method. Search the forums for that method, there are literally hundreds of posts on the subject. The search is in the upper right corner.

  • Problem outputting to the screen using  FileDescriptor.out

    I have the following program that reads prime numbers from a binary file. The issue is that the numbers are not printing to the screen using
    FormatWriter out = new FormatWriter(
           new BufferedWriter(
           new FileWriter(FileDescriptor.out)));The numbers are being read from the file as if I unblock the line
    // System.out.println(primes[j]); the numbers are printed to the screen.
    I have pasted the code below and the code that creates the prime numbers file.
    Thanks for any help.
    package readprimes;
    import java.io.*;
    public class ReadPrimes {
       public static void main(String[] args) {
           File myPrimes;
           DataInputStream primesIn;
            try{
                String directory = "C:/JunkData";
                String fileName = "Prime.bin";
                myPrimes = new File(directory, fileName);
                 primesIn = new DataInputStream(new FileInputStream(myPrimes));
            catch(FileNotFoundException e){
                return;
            catch(IOException e){
                return;
        FormatWriter out = new FormatWriter(
           new BufferedWriter(
           new FileWriter(FileDescriptor.out)));
            long[] primes = new long[6];
            boolean EOF = false;
            while(!EOF){
                int index = 0;
                try{
                    for(index = 0; index < primes.length; index++)
                        primes[index] = primesIn.readLong();
                       catch(IOException e){
                return;
    //             catch(EOFException e){
    //                 EOF =  true;
                for(int j = 0;j < index; j++){
             //       System.out.println(primes[j]);
                    out.print(primes[j]);
                    out.println();
    out.close();
    package readprimes;
    import java.io.PrintWriter;
    import java.io.*;
    public class FormatWriter extends PrintWriter{
        private int width = 10;
        public FormatWriter(Writer output){
            super(output);
        public FormatWriter(Writer output, int width){
            super(output);
            this.width = width;
        public FormatWriter(Writer output, boolean autoflush){
            super(output, autoflush);
            public FormatWriter(Writer output, boolean autoflush, int width){
            super(output, autoflush);
            this.width = width;
    Class that creates the prime number file
    package bufferedoutput;
    import java.io.*;
    public class TryPrimesOutput {
       public static void main(String[] args) {
           long[] primes = new long[200];
           primes[0] = 2;
           primes[1] = 3;
           int count = 2;
           long number = 5;
           outer:
           for(; count < primes.length; number +=2L)
               long limit = (long)Math.ceil(Math.sqrt((double)number));
               for(int i = 1; i <count && primes<= limit; i++)
    if(number%primes[i]==0)
    continue outer;
    primes[count++] = number;
    try
    String dirName = "c:\\JunkData";
    String fileName = "Prime.bin";
    File myPrimeDir = new File(dirName);
    if(!myPrimeDir.exists())
    myPrimeDir.mkdir();
    else
    if(!myPrimeDir.isDirectory())
    System.err.println();
    return;
    File primesFile = new File(myPrimeDir, fileName);
    primesFile.createNewFile();
    DataOutputStream primesStream = new DataOutputStream(
    new BufferedOutputStream(
    new FileOutputStream(primesFile)));
    for(int i = 0; i <primes.length;i++)
    primesStream.writeLong(primes[i]);
    primesStream.close();
    catch(IOException e){
    System.out.println("IOExcetoptj");

    Indeed. It isn't obvious to me what the result of new FileWriter(FileDescriptor.out) would result in, but your test appears to show that it doesn't result in something which can be used to output to the console.

  • How do I clear the screen in console application?

    In C or C++ we can clear the screen by clrscr() function.
    How can I acheive something similiar to this in Java

    Hi,
    Take a look at the below link may help you
    http://www.codeguru.com/forum/archive/index.php/t-323058.html
    This forum is exclusively related to discussions about Sun java Studio Creator. Henceforth please post these threads to an appropriate forum.
    MJ

  • Clearing the Screen in Xcode C

    Freinds:
    I am studying C using the Xcode standard application tool. Can someone list for me or e-mail me or pst here some code I can use to clear the screen in the simple "hello world!" application below?
    #include <stdio.h>
    int main (int argc, const char * argv[])
    printf("Hello, World!\n");
    return 0;
    Thanks in advance,
    Miguel Reznicek

    Basic C I/O is designed for a very basic command line. It won't do anything more than print. You could do something like:<pre>
    void clr()
    int i;
    for(i = 0; i < 100; ++i)
    printf("\n");
    }</pre>
    It isn't pretty, but it will always work.
    If you wanted to be a little more fancy and clever, you could access the terminal escape codes directly.<pre>
    void clr()
    printf("\033[2J");
    }</pre>
    The problem with this method is that it is dependent on your particular terminal. This example is supposed to work with an ANSI terminal. You may have to fiddle with it to get it to work. If you wanted to be really clever, you could find out what terminal you are using programatically, query the termcap database for the clr escape code, and print that. That's going to be pretty hard though.
    Another option would be to use the curses library. The best I can do for you here is to just post a link to the ncurses man page. Ncurses is a very powerful library and should do exactly what you need. It is essentially a library that does exactly what I mentioned before about querying the termcap database based on your particular terminal. I used an old MacOS version years ago. Once you figure out the basics, it is easy.

  • Is There a Way to Clear the Screen ???

    I am building a Class that is text (command line) based. Is there anyway to clear the screen (output) in such a class.
    Similar to what CLS does in DOS...

    See my response here:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=317191

  • How do I clear the Screen Saver?

    How do I clear the Screen Saver from showing the photos on my phone?

    You must have set it to use your photo stream as the screensaver. You can go into settings - screensaver to change to a different source.

  • Clearing the screen in dos?

    I am executing my programs in DOS and I was wondering if there was a way to clear the screen. I was hoping that this did not involve having JAVA execute DOS commands... But if that is the case, then how do you do that?
    Thanks

    By "the screen" I assume you mean the DOS box where you typed your "java ..." command? If so, the easiest way is to have your Java program execute System.out.println(""); 24 times in a row, or however many times it takes to make it blank. The next time the program writes output, though, it will be at the bottom of the screen. If you don't like that, are really anal, and have nothing better to do you can do some JNI (Java Native Interface aka C++) programming to fix that.

Maybe you are looking for

  • Need to send a mail while safty stock goes down

    Dear experts, I Need to send a mail to concern persion while stock goes down from safty stock. We plan to put a check at the point of MARD table updation, Because we not able to put a check at the all transaction codes, So please LET ME KNOW HOW TO P

  • General Ledger Changes with Orders open

    Good Day I have a material that was issued to a service order (IW32) and it went to the GL Account 5XXXXXX Cos Material. They decided they did not need this material so they cancelled the goods issue.  Whne the goods issue was cancelled it went to a

  • Conditional format in Matrix report

    Hi all, I have the column wise matrix output which I am require to put some highlight on the entire row if the condition meet. The output will be something like this :- Name ____________JOB A______JOB B _______JOB C AAAA____________2___________2_____

  • Error in UKM_GEN_WORKLIST

    Hi! How do we resolve this error in UKM_GEN_WORKLIST: "The current ABAP program "CL_UDM_BUPA_TRANSACTION_DATA==CP" had to be terminated because it has come across a statement that unfortunately cannot be executed" "An exception occurred that is expla

  • MenuKey functionality in  10.5/10.6?

    I have an OLD C/C++ program that I'm maintaining. It's still based on rsrc files and OS 9 system calls. (Yes, yes, I know. I'm TRYING to drag my company into the 21st century, but the other engineer is still using OSX10.3.9! please pity me) I'm tryin