Results 1 to 6 of 6
  1. #1
    acidblue is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default how to print output on same line in 'while loop'?

    I have a 'while loop' that prints on a new line everytime;
    system.out.println("bla bla bla:" + N)
    output i have:
    count 1
    count 2
    count 3......and so on

    what i want to do is print on the same line and display the count in real time,
    instead of on a new line.

    using 'print' instead of 'println' prints every thing all in one long line.
    I imagine i could clear/erase the line and print a new line in the 'while loop'
    but not sure how to do that.
    output i want:
    count x: have the numbers change in realtime instead of on a new line.

    right now it's a command line program but want to update to a gui/pop up box.

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    When you upgrade to a GUI, you will abandon System.out.println all together. The text box that you use inside of your GUI will have a text attribute and you will change that instead of printing the text. If I were you, I wouldn't worry about making this change when you are still running from the command line.

  3. #3
    acidblue is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default

    thanks for the reply.
    but to cure my curiosity was i at least on the right track?
    would still like to try it.

  4. #4
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    No, there is no way to change something that has already been printed to the console. Not unless you use some sort of a native library, java cant do that.

  5. #5
    dmacvittie is offline Member
    Join Date
    Aug 2007
    Posts
    30
    Rep Power
    0

    Default

    If you'd really like to try it, you could use the Curses for Java library... On SourceForge, but it hasn't been updated in five years - meaning either it's that good, or it's unsupported. I've used ncurses in C, never tried this in Java... Like is mentioned above, I go straight to the UI.

    Don.
    Don MacVittie F5 Networks - DevCentral

  6. #6
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Or the other solution is to create a wrapper with JNI, but for that you need quite a bit of Java AND C or C++ knowledge.

Similar Threads

  1. print line
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 01-26-2008, 02:05 PM
  2. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 10:34 PM
  3. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  4. Print XML tag
    By DonCash in forum XML
    Replies: 2
    Last Post: 08-07-2007, 06:02 PM
  5. Print A Pdf
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 05:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •