Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 6th, 2005, 11:58 AM
TetrisSmalls TetrisSmalls is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 2 TetrisSmalls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 50 sec
Reputation Power: 0
Press any key to continue

Hello all. I'm am pretty new to java programming. I am currently working on a program in class right now. What I wanted to know was, how do I do the code that says "Press any key to continue . . ." and it end the program after someone presses the any key ha. It is not required, but if I learn how to do it, I can incorporate it into my future programs in other ways as well. Thanks for the help.

Reply With Quote
  #2  
Old April 6th, 2005, 12:35 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Do your programs have any keyboard input?

The hard way would be to use InputStreams and ReadBuffers and all sorts of stuff you probably haven't learnt yet.
A better idea might be to ask your instructor. =)

I remember back in college we used a Java Class (provided by the text book) that took care of keyboard input.

We had to then do something like:
KeyboardInput kbd = new KeyboardInput();
System.out.println("Press ENTER key to continue...");
kbd.getChar();

note, this won't work for you as your Java compiler won't know what KeyboardInput is

The basic logic is, display the prompt and accept user input.
Our problem was "any key" wouldn't work, it had to be enter.

Again, I urge you to ask your instructor =)
I might be able to dig up those simple Class files that came with my textbook if you really want it.

Reply With Quote
  #3  
Old April 6th, 2005, 01:23 PM
TetrisSmalls TetrisSmalls is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 2 TetrisSmalls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 50 sec
Reputation Power: 0
We are given the MyInput class where it takes what the user types and I can store it. Essentially, I could make the program say "Press ENTER to continue..." but I just wanted to do like other programs that do the any key. I'll my ask my instructor tonight after class probably. Thanks for the help

Reply With Quote
  #4  
Old April 6th, 2005, 01:41 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Our solution back in college, with the java classes provided, only responded to ENTER.
If you do find the answer, be sure to post it here.

[although it might not do any good without your specific input classes]

Reply With Quote
  #5  
Old November 12th, 2008, 04:46 PM
BALANCEDMAN BALANCEDMAN is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 1 BALANCEDMAN User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 52 sec
Reputation Power: 0
If using scanners. try this out.

Prior to your system.out.println("Press enter to continue");
you have used a line of code that says nextInt() or nextLine() or something to that effect. To fix this problem use the following code:

Scanner keyIn = new Scanner(System.in);

System.out.print("Press the enter key to continue");
keyIn.nextLine();
keyIn.nextLine();

the first keyIn.nextLine will end the nextInt() or nextLine that was used before the System.out line and the 2nd will tell your code to continue onto the next portion when you hit enter.

Hope this was clear enough

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Press any key to continue


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap