An Experienced C/C++ programmer needs Java help

Hello, i have a little menu driven program on the Console. I was unsure and can't seem to find it, perhaps its my search terms, but how do you clear the console window? In C/C++ we'd use system("clear"); or system("cls"); depending on which OS was used. I greatly appreciate the help.

Thank you,
Jason
[hr]
We'll be an army of theives
Of self-freed slaves
Of mild-mannered maids
We'll fight with whispers and blades
So get ready, a new day is dawning
- The New Wild West -- Jewel

Comments

  • Check this out:
    http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20262077.html

    Iceman


    Efficiency:
    rawIn=(rawIn=(rawIn=br.readLine()).split("href="")[1]).split(""")[0];

  • Thanks but I am not gonna shell out cash for an answer.
    That site offers nothing free. But I appreciate your time.

    Thanks,
    Jason

    [hr]
    We'll be an army of theives
    Of self-freed slaves
    Of mild-mannered maids
    We'll fight with whispers and blades
    So get ready, a new day is dawning
    - The New Wild West -- Jewel

  • : Hello, i have a little menu driven program on the Console. I was unsure and can't seem to find it, perhaps its my search terms, but how do you clear the console window? In C/C++ we'd use system("clear"); or system("cls"); depending on which OS was used. I greatly appreciate the help.

    Take a look at Java's API
    http://java.sun.com/j2se/1.5.0/docs/api/

    I assume what you are doing is using a TextArea object, which extends
    TextComponent which has the following method:

    void setText(String t)
    Sets the text of this TextComponent to the specified text.

    Therefore I would take your take your TextComponent Object 'console' and use the following syntax:

    console.setText("")

    using "" as the null character.

    If this is not the case please post a snippet of your code for the object you are using.

    Hope this helps.
    Ashlungs
  • I'm not working directly with an object. I'm simply using System.out.print() and System.out.println() to write to the screen a few lines and would like to clear the screen before the next few sorta record like. But my code is not with me, sadly, and it is not relevent. This is just purely the console environment only. No GUI elements.

    Thanks,
    Jason
    [hr]
    We'll be an army of theives
    Of self-freed slaves
    Of mild-mannered maids
    We'll fight with whispers and blades
    So get ready, a new day is dawning
    - The New Wild West -- Jewel

  • That one isn't one you have to pay for; just scroll down. I wasn't willing to pay for it either :)

    Iceman


    Efficiency:
    rawIn=(rawIn=(rawIn=br.readLine()).split("href="")[1]).split(""")[0];

  • : I'm not working directly with an object. I'm simply using System.out.print() and System.out.println() to write to the screen a few lines and would like to clear the screen before the next few sorta record like. But my code is not with me, sadly, and it is not relevent. This is just purely the console environment only. No GUI elements.


    Ok, take a look at this page:
    http://www.rgagnon.com/javadetails/java-0047.html
    one caveat though, only the brute force method
    for (int i=0; i<25; i++)
    System.out.println();
    guarentees cross-platform portability, and its not very nifty at that.

    I would strongly suggest using java gui to deal with any io for just that reason. Just steal some code that fits the bill and customize it to your needs.

    :?)-~
    Ashlungs
  • [red]: Hello, i have a little menu driven program on the Console. I was unsure and can't seem to find it, perhaps its my search terms, but how do you clear the console window? In C/C++ we'd use system("clear"); or system("cls"); depending on which OS was used. I greatly appreciate the help. [/red]

    I understand there are 3rd party APIs that will do what you want (like a Java version of curses).

    You can roll your own with JNI (though you'll have to do this for every target platform).

    1) Create + compile the Java calling class
    [code]
    public class Clear {

    static {
    System.loadLibrary("Clear");
    }

    public static native void clear();

    public static void main(String[] args) throws Exception {
    clear();
    }
    }
    [/code]
    2) Create the header file using javah
    3) Create + compile the library implementation
    [code]
    #include "Clear.h"

    #include

    JNIEXPORT void JNICALL Java_Clear_clear(JNIEnv * env, jclass c)
    {
    system("cls");
    }

    [/code]

    I used MINGW32 (a Win32 version of gcc):
    [code]
    javac Clear.java
    javah Clear
    gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Ic:j2sdk1.4.2_04include -Ic:j2sdk1.4.2_04includewin32 -shared -o Clear.dll Clear.cpp
    [/code]

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • Ugggg....manipulating the console in java....

    Try this:
    System.out.println ((char)27 + "[2J");

    Not completely portable - make sure your shell is VT100-compatible (supports this ANSI escape sequence).








    : [red]: Hello, i have a little menu driven program on the Console. I was unsure and can't seem to find it, perhaps its my search terms, but how do you clear the console window? In C/C++ we'd use system("clear"); or system("cls"); depending on which OS was used. I greatly appreciate the help. [/red]
    :
    : I understand there are 3rd party APIs that will do what you want (like a Java version of curses).
    :
    : You can roll your own with JNI (though you'll have to do this for every target platform).
    :
    : 1) Create + compile the Java calling class
    : [code]
    : public class Clear {
    :
    : static {
    : System.loadLibrary("Clear");
    : }
    :
    : public static native void clear();
    :
    : public static void main(String[] args) throws Exception {
    : clear();
    : }
    : }
    : [/code]
    : 2) Create the header file using javah
    : 3) Create + compile the library implementation
    : [code]
    : #include "Clear.h"
    :
    : #include
    :
    : JNIEXPORT void JNICALL Java_Clear_clear(JNIEnv * env, jclass c)
    : {
    : system("cls");
    : }
    :
    : [/code]
    :
    : I used MINGW32 (a Win32 version of gcc):
    : [code]
    : javac Clear.java
    : javah Clear
    : gcc -Wall -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Ic:j2sdk1.4.2_04include -Ic:j2sdk1.4.2_04includewin32 -shared -o Clear.dll Clear.cpp
    : [/code]
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories