DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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.




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links