Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How Do I Detect if the User has pressed the ENTER key???

Reply
Thread Tools

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

 
 
Shanknbake
Guest
Posts: n/a
 
      10-07-2005
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

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-07-2005
On 7 Oct 2005 11:57:03 -0700, "Shanknbake" <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
 
Shanknbake
Guest
Posts: n/a
 
      10-08-2005
okay thanks...that helps a lot!! my program works flawlessly now

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-09-2005
On 8 Oct 2005 02:13:32 -0700, "Shanknbake" <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Control postback events when enter key is pressed jhoge123@yahoo.com ASP .Net 0 12-02-2004 02:21 PM
how to disable post back if enter key is pressed on th form gh0st54 ASP .Net 2 09-27-2004 06:41 PM
asp:Button click when Enter is pressed - help Timothy V ASP .Net 1 07-21-2004 06:34 AM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM



Advertisments