Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By quad64bit

Thread: How can I clear the screen?

  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default How can I clear the screen?

    I am making a command-line program using java.

    I have done the majority of the background work and now am working on the user interface.

    I am going to be asking things like "how old are you" and I will have the user type a line of text and press enter, with their input being saved as a variable.

    The thing I want to happen after this is the screen clearing (no text) so that the next question can be displayed without the screen looking confusing.

    Is there a way to do this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How can I clear the screen?

    There is no such command available in core Java. Consider creating a GUI if you absolutely need this functionality.

  3. #3
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How can I clear the screen?

    I read that this probably wasn't possible in java, I just wanted to make sure.

    In that case I'll have to use my backup solution of creating lots of newLines. I am not experienced enough for a GUI yet and for what I am doing I will not really benefit from it.

    Thank you for your help though.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How can I clear the screen?

    You're welcome.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How can I clear the screen?

    Furbarable said it, and is correct, however, there are packages designed to emulate this functionality (which is usually supplied by some variant of curses or ncurses in unix). The learning curve may be too steep for your level of experience, but check out the screenshots on the Charva project website: CHARVA: A Java Windowing Toolkit for Text Terminals

    You can do simple things like in-place text changes and clearing the screen, as well as advanced stuff like simulating tabs, fields, etc...

    If you MUST use a command line, this is the way to go, but as others have said, making a simple GUI window which does the same thing would be much easier. Packages like this are still popular for command line servers/systems though!
    Fubarable likes this.

  6. #6
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How can I clear the screen?

    How difficult would it be to have everything which is currently command-line but in a JFrame?

    All I would need is a single window and one line of text input (i.e. what a command-line window is).

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How can I clear the screen?

    You could just have a textfield and a text area - where input is the textfield and all output is in the text field.

  8. #8
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How can I clear the screen?

    So what do I need to start learning to do that? Swing?


    Will it take too long to learn?

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: How can I clear the screen?

    Define "too long".
    It'll probably take about the same amount of time as to learn a curses/ncurses wrapper.
    Here's the tutorial(s).
    Skip the Netbeans IDE bit, as the GUI builder will not do you any favours.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to clear screen in JAVA ??
    By ProgRookie92 in forum New To Java
    Replies: 3
    Last Post: 07-03-2012, 09:00 PM
  2. clear screen in java
    By chandrasekhar.melam in forum New To Java
    Replies: 7
    Last Post: 09-25-2011, 03:32 PM
  3. is there any method for clear screen?
    By chandrasekhar.melam in forum New To Java
    Replies: 9
    Last Post: 09-22-2011, 08:32 PM
  4. Need For Clear Screen
    By adithya4u4ever in forum New To Java
    Replies: 8
    Last Post: 03-08-2009, 08:41 AM
  5. Clear screen in java
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 09:43 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
  •