libConsole/Getch.java
author Markus Brökers <mbroeker@largo.homelinux.org>
Wed, 18 Aug 2010 18:17:51 +0200
changeset 143 88d9b8bfa7a5
parent 55 2a20d0184041
permissions -rw-r--r--
a md5 demo is already in lsflib/tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
import java.io.*;
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
public class Getch {
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
    public static void main (String args[]) {
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
        int c;
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
        System.out.println ("Press q or ESCAPE to quit");
55
2a20d0184041 Console aborts with return code -1 on error
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 49
diff changeset
     8
49
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
        for (;;) {
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
            c = Console.getch ();
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
            switch (c) {
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
            case 27:
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
            case 'q':
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
                System.exit (0);
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
                break;
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
            default:
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
                System.out.printf ("KEY: %c (%d)\n", c, c);
55
2a20d0184041 Console aborts with return code -1 on error
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 49
diff changeset
    18
                break;
49
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
            }
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
        }
77094ec383cf libConsole: a java native interface example
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
    };
55
2a20d0184041 Console aborts with return code -1 on error
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 49
diff changeset
    22
}