Programming a Console application

I want to program a text-based java application (with menus and navigating using tab and the arrow keys, a program like microsoft's "edit" dos program)

Is this possible?

Any info would be appreciated.

Thanks
LVL 3
missilesiloAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WebstormCommented:
Hi missilesilo,

Edit directly use video memory. You cannot do the same with Java.

You can use ANSI codes :

http://en.wikipedia.org/wiki/ANSI_escape_code
http://rrbrandt.dyndns.org:60000/docs/tut/redes/ansi.php
WebstormCommented:
Mayank SAssociate Director - Product EngineeringCommented:
You want to make a UI using AWT/ Swing?

http://java.sun.com/docs/books/tutorial/uiswing/index.html
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

missilesiloAuthor Commented:
How would I use these ANSI codes in Java?
WebstormCommented:
For example:
    System.out.print("\033[44;37;1m  File  "); // "  File  " white on blue background

    System.out.print("\033[2J"); // clear the screen

    System.out.print("\033[10;7H"); // move cursor to row 10 column 7

missilesiloAuthor Commented:
Hmm... Here is the output of the program: (running under Microsoft Windows 2000 [Version 5.00.2195] command prompt)

C:\Documents and Settings\Administrator\ConsoleApp\dist>java -jar ConsoleApp.jar

←[44;37;1m  File
C:\Documents and Settings\Administrator\ConsoleApp\dist>java -jar ConsoleApp.jar

←[2J
C:\Documents and Settings\Administrator\ConsoleApp\dist>java -jar ConsoleApp.jar

←[10;7H
Jim CakalicSenior Developer/ArchitectCommented:
Not sure that a pure Java way exists. However, there is a Java bridge to ncurses called jcurses that you might try:
http://sourceforge.net/projects/javacurses/

Here's a link to a 'starter' application on JavaWorld:
http://www.javaworld.com/javaworld/javaqa/2002-12/02-qa-1220-console.html

Regards,
Jim

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
missilesiloAuthor Commented:
   public static void main(String[] args) throws Exception {
       
        Window w = new Window(40, 20, true, "Hello World Window");

        DefaultLayoutManager mgr = new DefaultLayoutManager();
        mgr.bindToContainer(w.getRootPanel());
        mgr.addWidget(
            new Label("Hello World!", new CharColor(CharColor.WHITE, CharColor.GREEN)),
            0, 0, 40, 20,
            WidgetsConstants.ALIGNMENT_CENTER,
            WidgetsConstants.ALIGNMENT_CENTER);

        w.show();
        Thread.currentThread().sleep(5000);
        w.close(); // reset the native console

    }


java.lang.ExceptionInInitializerError
        at jcurses.system.InputChar.<clinit>(InputChar.java:25)
        at jcurses.widgets.Window.<clinit>(Window.java:209)
        at consoleapp.Main.main(Main.java:78)
Caused by: java.lang.NullPointerException
        at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)
        at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
        ... 3 more
Exception in thread "main"
Java Result: 1
Jim CakalicSenior Developer/ArchitectCommented:
There's a libjcurses.dll that should have come down with the jar. It needs to be in the same directory as the jcurses.jar (doesn't matter whether it's on the java.library.path because of the way that it is found).
missilesiloAuthor Commented:
Hmm. I'm not sure what I'm doing wrong:

------

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>dir
 Volume in drive C has no label.
 Volume Serial Number is 4C71-5688

 Directory of C:\DOCUME~1\ADMINI~1\ConsoleApp\dist

04/27/2006  08:10p      <DIR>          .
04/27/2006  08:10p      <DIR>          ..
04/27/2006  08:08p             107,192 ConsoleApp.jar
11/24/2002  01:50p              86,542 jcurses.jar
11/24/2002  01:50p              59,392 libjcurses.dll
               3 File(s)        253,126 bytes
               2 Dir(s)  28,909,268,992 bytes free

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>java -jar ConsoleApp.jar
Exception in thread "main" java.lang.ExceptionInInitializerError
        at jcurses.system.InputChar.<clinit>(InputChar.java:25)
        at jcurses.widgets.Window.<clinit>(Window.java:209)
        at consoleapp.Main.main(Main.java:78)
Caused by: java.lang.NullPointerException
        at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)
        at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
        ... 3 more

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>

------

ConsoleApp.jar is my application... its manifest file is:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_05-b05 (Sun Microsystems Inc.)
Main-Class: consoleapp.Main
Class-Path: jcurses.jar
X-COMMENT: Main-Class will be added automatically by build

Jim CakalicSenior Developer/ArchitectCommented:
Haven't tried it with -jar ... Maybe try setting class-path to include current working directory? That or temporarily unjar and invoke the main class?
missilesiloAuthor Commented:
Ok I extracted it... jcurses.jar and the dll file are in the current directory:

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>java consoleapp.Main
Exception in thread "main" java.lang.NoClassDefFoundError: jcurses/widgets/Widge
tContainer

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>set classpath=jcurses.jar;.;%CLASSPATH%;

C:\DOCUME~1\ADMINI~1\ConsoleApp\dist>java consoleapp.Main
Exception in thread "main" java.lang.ExceptionInInitializerError
        at jcurses.system.InputChar.<clinit>(InputChar.java:25)
        at jcurses.widgets.Window.<clinit>(Window.java:209)
        at consoleapp.Main.main(Main.java:78)
Caused by: java.lang.NullPointerException
        at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)
        at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)
        ... 3 more
missilesiloAuthor Commented:
Well, I got it working!

Don't know what was wrong with their code but I saved libjcurses.dll on my c:\ drive and changed the System.load(getLibraryPath()) to System.load("c:\\libjcurses.dll") under Toolkit.java and it worked.

Jim CakalicSenior Developer/ArchitectCommented:
I can duplicate the problem when I have jcurses.jar and libjcurses.dll in the same folder as the application classes. When I put them in a separate folder (say, C:/local/lib where I frequently put common jars and dlls) then I can run just fine using:
    java -classpath .;C:/local/lib/jcurses.jar JCursesTest

Not sure. May be a defect in the Toolkit.getLibraryPath method as it tries to determine the path to fine the dll.

Jim
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.