On Sun, 18 Jul 2010 10:59:06 +0000, Stefan Ram wrote:
Mike Barnard<m.barnard.trousers@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.