Prev: Prestige of developers
Next: Newbie again. "Java Keyboard input" is a failure as a googlesearch. What isn't?
From: Mike Barnard on 18 Jul 2010 11:54 On 18 Jul 2010 12:45:26 GMT, ram(a)zedat.fu-berlin.de (Stefan Ram) wrote: >Andreas Leitgeb <avl(a)gamma.logic.tuwien.ac.at> writes: >>And the javadoc on java.lang.System's field "in" is another approach. > > Yes. But I wonder: Does anyone know a well-known Java > program (a program that is used by many people) that reads > what a user types with the keyboard from System.in? > > Even if someone would come up with such a program here, > I think they are very rare. > > (There are several that read the command line arguments as in > >main( final java.lang.String[] args ) > > , but this does not use System.in.) > > So why should I recommend something that I deem to be used > hardly ever in applied programming? Thanks for the warning, I won't go that way just yet.
From: Mike Barnard on 18 Jul 2010 11:59 On Sun, 18 Jul 2010 13:04:29 +0100, Tom Anderson <twic(a)urchin.earth.li> wrote: >On Sun, 18 Jul 2010, Mike Barnard wrote: > >> As some of you may remember from a couple of other recent newbie posts, >> I'm trying to teach myself, slowly, by book. As in previous posts can >> you give me some guidance please? >> >> Currently I want to learn about reading input from the keyboard. Doing >> a google search for "Java keyboard input" and similar hasn't brought >> me to the nirvana I'd like. I know it must be there, but where? > >I assume you're not talking about doing this in a GUI, but from the Correctamondo... >command line. In that case, it might help to know that this interface >is usually called the 'console', and occasionally the 'terminal'. >Searching for 'java console input' should be more helpful. Done, more tutorials to choose from. I might have some idea of what I'm talking about eventually! >I'll give a further steer that the two things you're interested in are >System.in and java.util.Scanner. Someone above says system.in isn't used much. Is this because it's too low level and everyone else uses GUI stuff? >> What I do get are hits such as: >> >> http://wiki.erland.homeip.net/index.php/Java_Tutorial_Lesson_12:_Keyboard_input >> which is part way through something else, >> >> http://www.pp.rhul.ac.uk/~george/PH2150/html/node13.html >> This says what, but not why, > >What do you mean by that? The second one? I mean it shows some code and says "do it like this". It doesn't explain why this is any better or worse than any other way. There is no tutorial, just parrot fashion "do it". (But I haven't yet read it in depth, SIMBW.) >tom I thought Java was case sensitive? :)
From: Mike Barnard on 18 Jul 2010 12:07 On Sun, 18 Jul 2010 06:19:17 -0700, Roedy Green <see_website(a)mindprod.com.invalid> wrote: >On Sun, 18 Jul 2010 11:50:45 +0100, Mike Barnard ><m.barnard.trousers(a)thunderin.co.uk> wrote, quoted or indirectly >quoted someone who said : > >>Hi all. >> >>As some of you may remember from a couple of other recent newbie >>posts, I'm trying to teach myself, slowly, by book. As in previous >>posts can you give me some guidance please? >> >>Currently I want to learn about reading input from the keyboard. Doing >>a google search for "Java keyboard input" and similar hasn't brought >>me to the nirvana I'd like. I know it must be there, but where? >> >>What I do get are hits such as: >> >>http://wiki.erland.homeip.net/index.php/Java_Tutorial_Lesson_12:_Keyboard_input >>which is part way through something else, >> >>http://www.pp.rhul.ac.uk/~george/PH2150/html/node13.html >>This says what, but not why, >> >>http://www.brighthub.com/internet/web-development/articles/16220.aspx >>3d on the web... and very high on the list of Google responses. >> >>Of course, working through them I'm sure I can come to some sort of >>realisation of what it entails, but I'm looking for the full >>explanation. >> >>My book, Head First Java, doesn't have "keyboard" in the index. The >>only "Input" in the index is "InputStreamReader" which is used in >>reference to reading data from a socket. >> >>[An "aha!" moment] I've just found a document in the Java Tutorials >>called basic i/o. This may be my nirvana but in case not I'll post >>this anyway. >> >>So, can the Fount Of All Knowledge point me to a good tutorial on the >>most efficient methods to get input from a user please? I don't expect >>hand holding, honestly, just pointers to really useful tutorials. >> >>Thanks in advance. >> >>Mike. > >see http://mindprod.com/products1.html#KEYPLAYER >for how to read the keyboard at a low level. I find Mindprod but not Keyplayer... >Normally you do it with components such as JTextField and brethren. >See http://mindprod.com/jgloss/jtextfield.html I see this. More learning... hello brain, take this! Thanks.
From: Mike Barnard on 18 Jul 2010 12:08 On 18 Jul 2010 16:35:53 +0300, Jussi Piitulainen <jpiitula(a)ling.helsinki.fi> wrote: >Mike Barnard writes: > >> Hi all. >> >> As some of you may remember from a couple of other recent newbie >> posts, I'm trying to teach myself, slowly, by book. As in previous >> posts can you give me some guidance please? >> >> Currently I want to learn about reading input from the keyboard. Doing >> a google search for "Java keyboard input" and similar hasn't brought >> me to the nirvana I'd like. I know it must be there, but where? > >You might find something relevant with "java readline" or "java >editline" or "java jline". These lead to a couple of libraries that >provide an editable command line, including history. > >I used one of these a few years ago - jline, I think - on some >GNU/Linux system. Thanks.
From: Mike Barnard on 19 Jul 2010 02:58 On Sun, 18 Jul 2010 22:48:28 -0400, Arne Vajh�j <arne(a)vajhoej.dk> wrote: >On 18-07-2010 11:52, Simon Brooke wrote: >> On Sun, 18 Jul 2010 10:59:06 +0000, Stefan Ram wrote: >> >>> Mike Barnard<m.barnard.trousers(a)thunderin.co.uk> writes: >>>> So, can the Fount Of All Knowledge point me to a good tutorial on the >>>> most efficient methods to get input from a user please? I don't expect >>>> hand holding, honestly, just pointers to really useful tutorials. >>> >>> To get text from the keyboard, the most obvious means to me would be a >>> javax.swing.JTextField. >> >> Errrrr.... WHY?!?!?!? >> >> It seems perverse to go to the overhead of building a complete WIMP user >> interface to do >> >> for ( int c = System.in.read(); c> -1; c = System.in.read()) { >> char ch = (char) c; >> /* now do something with ch */ >> } >> >> In practice something like the following would be more useful: >> >> string readLineFromStdin() { >> StringBuffer buffy = new StringBuffer(); >> bool reading = true; >> >> while ( reading) { >> int c = System.in.read(); >> >> switch (c) { >> case 10: >> case 13: >> case -1: >> reading = false; >> break; >> default: >> buffy.append( (char)c); >> break; >> } >> } >> return buffy.toString(); >> } >> >> although in anything but the simplest utility programs you'd probably do >> something a touch more sophisticated than that. > >No - you would do it a lot simpler than that in any program. > >BufferedReader or Scanner will save a lot of code. As I'm finding out, thanks. However, would the above teach me anything about 'how it works' even if it is overly wordy? >Arne
First
|
Prev
|
Pages: 1 2 Prev: Prestige of developers Next: Newbie again. "Java Keyboard input" is a failure as a googlesearch. What isn't? |