Keyboard input


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Keyboard input

  1. #1
    Azzi Guest

    Keyboard input


    How can I stop my console application using keyboard input (for example "q")
    without blocking process.

  2. #2
    Guest

    Re: Keyboard input

    If I understand your question correctly (and I probably don't)....you want
    to quit the application from the command prompt once the letter q is
    entered. All you need to do is read the input, and if the input matches
    then call System.exit().

    ie.

    import java.io.*;
    public class sysIn {

    public static void main(String args[]) {
    try {
    BufferedReader in = new BufferedReader(new
    InputStreamReader(System.in));
    System.out.print("Name:");
    String s1 = in.readLine();

    if(s1.equals("q"))
    System.exit(0);

    System.out.println("this is the end");
    }
    catch (IOException io) {}
    }

    }



    "Azzi" <nikitab@moscow.vestedev.com> wrote in message
    news:3a8fba52$1@news.devx.com...
    >
    > How can I stop my console application using keyboard input (for example

    "q")
    > without blocking process.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center