How Do I Detect if the User has pressed the ENTER key???

Discussion in 'Java' started by Shanknbake, Oct 7, 2005.

  1. Shanknbake

    Shanknbake Guest

    Hi, this is my first java class..and I'm writing a program in which i
    need to allow the user to "continue by pressing the enter key, or q to
    quit"...how to I check if the user has entered the enter key?

    Code:

    do
    {
    //...body code
    //...body code
    //bottom of do/while statement

    System.out.println("If you would like to quit, type 'q', otherwise
    press any [enter] to continue");
    quit=keyboard.next();


    }
    while(quit.equalsIgnoreCase("\n")); //how do i check if enter key
    is pressed?
    }
    }...

    quit is a String variable...not a char
    plz help this
    thanks
     
    Shanknbake, Oct 7, 2005
    #1
    1. Advertising

  2. Shanknbake

    Roedy Green Guest

    On 7 Oct 2005 11:57:03 -0700, "Shanknbake" <>
    wrote or quoted :

    >Hi, this is my first java class..and I'm writing a program in which i
    >need to allow the user to "continue by pressing the enter key, or q to
    >quit"...how to I check if the user has entered the enter key?


    Java console does not support key by key reading. It supports line by
    line reading.

    See http://mindprod.com/applets/fileio.html
    for details

    And empty line is "" length 0 which is just an entry without other
    data.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 7, 2005
    #2
    1. Advertising

  3. Shanknbake

    Shanknbake Guest

    okay thanks...that helps a lot!! my program works flawlessly now :)
     
    Shanknbake, Oct 8, 2005
    #3
  4. Shanknbake

    Roedy Green Guest

    On 8 Oct 2005 02:13:32 -0700, "Shanknbake" <>
    wrote or quoted :

    >okay thanks...that helps a lot!! my program works flawlessly now :)


    Good. Iove it when a student can run with the ball given just a small
    clue like that.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 9, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gh0st54
    Replies:
    2
    Views:
    7,347
    gh0st54
    Sep 27, 2004
  2. Replies:
    0
    Views:
    362
  3. =?Utf-8?B?RGlmZmlkZW50?=

    button click event when keyboard's enter key is pressed

    =?Utf-8?B?RGlmZmlkZW50?=, Dec 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,876
    Steve C. Orr [MVP, MCSD]
    Dec 20, 2004
  4. Rune
    Replies:
    6
    Views:
    1,312
    Richie Hindle
    Jan 29, 2004
  5. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    439
    Anders Matthiessen
    Jan 12, 2005
Loading...

Share This Page