Link to home
Start Free TrialLog in
Avatar of missilesilo
missilesilo

asked on

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
Avatar of Webstorm
Webstorm

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
Avatar of Mayank S
You want to make a UI using AWT/ Swing?

http://java.sun.com/docs/books/tutorial/uiswing/index.html
Avatar of missilesilo

ASKER

How would I use these ANSI codes in Java?
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

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
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
   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
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).
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

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?
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
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.

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