Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 User input
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Sun Jul 21, 2013 9:01 pm   Post subject: User input

Just a quick question, is there a function in Java that's like getch and hasch in turing?
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Sun Jul 21, 2013 9:05 pm   Post subject: RE:User input

You probably want the java.util.Scanner class, as long as you're using Java 1.5 (aka Java 5) or better. If you're using an ancient version of Java, such as the 1.4.2 that ships with Ready to Program, then you should upgrade, preferably to at least Java 6 (aka 1.6).
nullptr




PostPosted: Sun Jul 21, 2013 9:54 pm   Post subject: Re: User input

I'm not too familiar with Turing but it looks like getch is the same as in C++: you get a character without waiting for the end of the line. I'm pretty sure there's no way to do that in Java: System.in is an instance of InputStream ( http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html ) and the most low-level way to get a character is with System.in.read(). However, that method waits for the end of the line, so I think you're out of luck.
DemonWasp




PostPosted: Sun Jul 21, 2013 11:37 pm   Post subject: Re: User input

nullptr @ Sun Jul 21, 2013 9:54 pm wrote:
... most low-level way to get a character is with System.in.read(). However, that method waits for the end of the line, so I think you're out of luck.


False. InputStream.read() will read a single byte from its source (notably, not a character, which can be more than one byte).

Notably, though, Java's System.in is a typically attached to a line-oriented reader, and that is what will wait until the end of the line. I suppose it's possible to connect something else, but I've never seen that.

If you want to read keyboard input character by character, then you may want to look at AWT, Swing, or SWT. For example, try this: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html . If you aren't familiar with GUI programming, you may find that kind of thing difficult.
Raknarg




PostPosted: Mon Jul 22, 2013 4:48 pm   Post subject: RE:User input

I'm familiar with event based programming if that's what you mean. Like visual basic, or ones of my own making
Raknarg




PostPosted: Mon Jul 22, 2013 4:51 pm   Post subject: RE:User input

Thanks for the input. Learning new languages is so frustrating when I don't even know most syntax -.-'
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: