Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2567
  • Last Modified:

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
0
missilesilo
Asked:
missilesilo
  • 6
  • 4
  • 3
  • +1
1 Solution
 
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
0
 
WebstormCommented:
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You want to make a UI using AWT/ Swing?

http://java.sun.com/docs/books/tutorial/uiswing/index.html
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

0
 
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
0
 
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
0
 
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
0
 
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).
0
 
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

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

0
 
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now