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
Is this possible?
Any info would be appreciated.
Thanks
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
System.out.print("\033[44;
System.out.print("\033[2J"
System.out.print("\033[10;
ASKER
Hmm... Here is the output of the program: (running under Microsoft Windows 2000 [Version 5.00.2195] command prompt)
C:\Documents and Settings\Administrator\Con soleApp\di st>java -jar ConsoleApp.jar
←[44;37;1m File
C:\Documents and Settings\Administrator\Con soleApp\di st>java -jar ConsoleApp.jar
←[2J
C:\Documents and Settings\Administrator\Con soleApp\di st>java -jar ConsoleApp.jar
←[10;7H
C:\Documents and Settings\Administrator\Con
←[44;37;1m File
C:\Documents and Settings\Administrator\Con
←[2J
C:\Documents and Settings\Administrator\Con
←[10;7H
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.getR ootPanel() );
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().sle ep(5000);
w.close(); // reset the native console
}
java.lang.ExceptionInIniti alizerErro r
at jcurses.system.InputChar.< clinit>(In putChar.ja va:25)
at jcurses.widgets.Window.<cl init>(Wind ow.java:20 9)
at consoleapp.Main.main(Main. java:78)
Caused by: java.lang.NullPointerExcep tion
at jcurses.system.Toolkit.get LibraryPat h(Toolkit. java:111)
at jcurses.system.Toolkit.<cl init>(Tool kit.java:3 7)
... 3 more
Exception in thread "main"
Java Result: 1
Window w = new Window(40, 20, true, "Hello World Window");
DefaultLayoutManager mgr = new DefaultLayoutManager();
mgr.bindToContainer(w.getR
mgr.addWidget(
new Label("Hello World!", new CharColor(CharColor.WHITE,
0, 0, 40, 20,
WidgetsConstants.ALIGNMENT
WidgetsConstants.ALIGNMENT
w.show();
Thread.currentThread().sle
w.close(); // reset the native console
}
java.lang.ExceptionInIniti
at jcurses.system.InputChar.<
at jcurses.widgets.Window.<cl
at consoleapp.Main.main(Main.
Caused by: java.lang.NullPointerExcep
at jcurses.system.Toolkit.get
at jcurses.system.Toolkit.<cl
... 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).
ASKER
Hmm. I'm not sure what I'm doing wrong:
------
C:\DOCUME~1\ADMINI~1\Conso leApp\dist >dir
Volume in drive C has no label.
Volume Serial Number is 4C71-5688
Directory of C:\DOCUME~1\ADMINI~1\Conso leApp\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\Conso leApp\dist >java -jar ConsoleApp.jar
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at jcurses.system.InputChar.< clinit>(In putChar.ja va:25)
at jcurses.widgets.Window.<cl init>(Wind ow.java:20 9)
at consoleapp.Main.main(Main. java:78)
Caused by: java.lang.NullPointerExcep tion
at jcurses.system.Toolkit.get LibraryPat h(Toolkit. java:111)
at jcurses.system.Toolkit.<cl init>(Tool kit.java:3 7)
... 3 more
C:\DOCUME~1\ADMINI~1\Conso leApp\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
------
C:\DOCUME~1\ADMINI~1\Conso
Volume in drive C has no label.
Volume Serial Number is 4C71-5688
Directory of C:\DOCUME~1\ADMINI~1\Conso
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\Conso
Exception in thread "main" java.lang.ExceptionInIniti
at jcurses.system.InputChar.<
at jcurses.widgets.Window.<cl
at consoleapp.Main.main(Main.
Caused by: java.lang.NullPointerExcep
at jcurses.system.Toolkit.get
at jcurses.system.Toolkit.<cl
... 3 more
C:\DOCUME~1\ADMINI~1\Conso
------
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?
ASKER
Ok I extracted it... jcurses.jar and the dll file are in the current directory:
C:\DOCUME~1\ADMINI~1\Conso leApp\dist >java consoleapp.Main
Exception in thread "main" java.lang.NoClassDefFoundE rror: jcurses/widgets/Widge
tContainer
C:\DOCUME~1\ADMINI~1\Conso leApp\dist >set classpath=jcurses.jar;.;%C LASSPATH%;
C:\DOCUME~1\ADMINI~1\Conso leApp\dist >java consoleapp.Main
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at jcurses.system.InputChar.< clinit>(In putChar.ja va:25)
at jcurses.widgets.Window.<cl init>(Wind ow.java:20 9)
at consoleapp.Main.main(Main. java:78)
Caused by: java.lang.NullPointerExcep tion
at jcurses.system.Toolkit.get LibraryPat h(Toolkit. java:111)
at jcurses.system.Toolkit.<cl init>(Tool kit.java:3 7)
... 3 more
C:\DOCUME~1\ADMINI~1\Conso
Exception in thread "main" java.lang.NoClassDefFoundE
tContainer
C:\DOCUME~1\ADMINI~1\Conso
C:\DOCUME~1\ADMINI~1\Conso
Exception in thread "main" java.lang.ExceptionInIniti
at jcurses.system.InputChar.<
at jcurses.widgets.Window.<cl
at consoleapp.Main.main(Main.
Caused by: java.lang.NullPointerExcep
at jcurses.system.Toolkit.get
at jcurses.system.Toolkit.<cl
... 3 more
ASKER
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:\\libjcurse s.dll") under Toolkit.java and it worked.
Don't know what was wrong with their code but I saved libjcurses.dll on my c:\ drive and changed the System.load(getLibraryPath
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
java -classpath .;C:/local/lib/jcurses.jar
Not sure. May be a defect in the Toolkit.getLibraryPath method as it tries to determine the path to fine the dll.
Jim
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