Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

raw input in Java?

920 views
Skip to first unread message

Ken

unread,
Feb 15, 1999, 3:00:00 AM2/15/99
to
Hello,
Is there a way to get raw input from the keyboard in Java? For
a lot of things, it would be much more convenient to validate
each character as it's typed by the user, instead of waiting for
<enter> then parsing the entire input string. Unfortunately, all
the books I've looked at don't address this - they assume you
want to wait for the user to press <enter> before processing
input from the keyboard. Any way around this?

Thanks,
Ken

William Brogden

unread,
Feb 15, 1999, 3:00:00 AM2/15/99
to
If you install a KeyListener, you can watch every key press,
key release and key typed event. You can alter them before
they are processed by the TextComponent.

This was all added with Java 1.1

WBB

Jerry McBride

unread,
Feb 17, 1999, 3:00:00 AM2/17/99
to
In article <36C8B2B9...@bga.com>,

William Brogden <wbro...@bga.com> wrote:
>If you install a KeyListener, you can watch every key press,
>key release and key typed event. You can alter them before
>they are processed by the TextComponent.
>
>This was all added with Java 1.1
>


Please, allow me to qualify that... just a tad. What you said is exactly
correct, from an app using the AWT. However, if one only wish keyboard input
from STD via a textmode app, then pressing the return key is the ONLY way
you'll get the key strokes from the user... A very good example of POOR JVM
design...

--

/--------------------\
| Jerry McBride |
| mcbr...@erols.com |
\--------------------/


Peter van der Linden

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
> However, if one only wish keyboard input
> from STD via a textmode app, then pressing the return key is the ONLY way
> you'll get the key strokes from the user... A very good example of POOR JVM
> design...

Yes, absolutely. I wrote the class Jot to simplify this for
people new to Java. Jot is simples to use, and it pops up a "jot pad"
in your otherwise non-GUI program. Anything you type on the jot pad
is sent straight to your program, keystroke by keystroke.

Jot is available at the same place as the Java FAQ: http://www.afu.com

Jerry McBride

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
In article <7ahgcm$hq2$1...@shell15.ba.best.com>,

pv...@best.com (Peter van der Linden) wrote:
>> However, if one only wish keyboard input
>> from STD via a textmode app, then pressing the return key is the ONLY way
>> you'll get the key strokes from the user... A very good example of POOR JVM
>> design...
>
>Yes, absolutely. I wrote the class Jot to simplify this for
>people new to Java. Jot is simples to use, and it pops up a "jot pad"
>in your otherwise non-GUI program. Anything you type on the jot pad
>is sent straight to your program, keystroke by keystroke.
>

Pete,
Out of haste I went and grabbed Jot.java. Thanks, but I have a question or two.
First off, does this require JDK1.2 and is Jot a GUI entity? If so, I'm still
in the cold for my text mode apps that wish to process keys as entered by the
user... My applications run on 1.1.x and text mode only... No GUI to speak of.

Thanks again.

Peter van der Linden

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
>Out of haste I went and grabbed Jot.java. Thanks, but I have a question or two.
>First off, does this require JDK1.2 and is Jot a GUI entity? If so, I'm still

It requires JDK 1.1 and up. There is nothing JDK 1.2 specific in it.

Jot is a GUI entity. No getting around that.
It is for people who want char-by-char input but are not ready to
dive into AWT programming just yet. So it won't be suitable for someone
who wants to avoid all GUIs completely.

It's mostly intended to help out students who are at one particular
phase of learning Java. They want char-by-char input but they haven't
reached the chapter on JTextFields yet.


Ken

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to Peter van der Linden
Peter van der Linden wrote:
>
> Jot is a GUI entity. No getting around that.
> It is for people who want char-by-char input but are not ready to
> dive into AWT programming just yet.

What are the chances that Java will some day support non-buffered
input in non-GUI mode? Sometimes it is very convenient to process
each character as it's entered, and also convenient to run from a
command line. Any chance that Sun might agree enough to add a non-
buffered input stream to java.io.*?

Thanks,
Ken

Jerry McBride

unread,
Feb 18, 1999, 3:00:00 AM2/18/99
to
In article <7aie6u$mgq$1...@shell15.ba.best.com>,

pv...@best.com (Peter van der Linden) wrote:
>>Out of haste I went and grabbed Jot.java. Thanks, but I have a question or two.
>>First off, does this require JDK1.2 and is Jot a GUI entity? If so, I'm still
>
>It requires JDK 1.1 and up. There is nothing JDK 1.2 specific in it.
>

My reasoning for asking about the JDK1.2 specificness is that Jot.java will not
compile on my OS/2 with JDK117. Javac complains it can't find the class
java.util.ArrayList during the import... I'll track this class down and see
what it's all about. Thanks.

Brent A Ellingson

unread,
Feb 19, 1999, 3:00:00 AM2/19/99
to
Jerry McBride (mcbr...@erols.com) wrote:

: Please, allow me to qualify that... just a tad. What you said is exactly
: correct, from an app using the AWT. However, if one only wish keyboard input


: from STD via a textmode app, then pressing the return key is the ONLY way
: you'll get the key strokes from the user... A very good example of POOR JVM
: design...

I'm sorry, but this has nothing at all to do with "poor JVM design".

The lack of character at-a-time input is is no different than C or
C++, or for that matter, any other programming language I've ever
used.

I'll gladly admit that some good (and _most_ bad) implementations of
those languages have added non-standard libraries to do character at
a time input. Since some vendors make little effort to sort their
non-standard libraries out from the standard ones, people are often
extremely suprised to discover what their favorite language actually
supports.

Anyhow, to get you started, there is "JCurses" by Piotr Gucwa, at
http://www.geocities.com/SiliconValley/Grid/1239/ To be honest,
I've never used it. If it works well for you, please let us know.

--
Brent Ellingson (bell...@badlands.NoDak.edu)
"It is amazing how complete is the delusion that beauty is goodness."
-- Leo Tolstoy

Jerry McBride

unread,
Feb 20, 1999, 3:00:00 AM2/20/99
to
In article <7aip8g$sta$1...@node2.nodak.edu>,

bell...@badlands.NoDak.edu (Brent A Ellingson) wrote:
>Jerry McBride (mcbr...@erols.com) wrote:
>
>: Please, allow me to qualify that... just a tad. What you said is exactly
>: correct, from an app using the AWT. However, if one only wish keyboard input
>: from STD via a textmode app, then pressing the return key is the ONLY way
>: you'll get the key strokes from the user... A very good example of POOR JVM
>: design...
>
>I'm sorry, but this has nothing at all to do with "poor JVM design".
>

I dissagree. Not only is it missing, there's no easy way of adding it into
your applications without using native methods. It's a glaring oversight that
would be easy enough to fix. Whether Sun realizes it or not, there is more to
writing applications than sticking strictly with the GUI...

--- snip ---

>Anyhow, to get you started, there is "JCurses" by Piotr Gucwa, at
>http://www.geocities.com/SiliconValley/Grid/1239/ To be honest,
>I've never used it. If it works well for you, please let us know.
>

If it's not in the JDK, I can't use it.

Jerry McBride

unread,
Feb 20, 1999, 3:00:00 AM2/20/99
to
In article <36CCD859.3DBD@locked_and_loaded.reno.nv.us>,

AMEN BROTHER! I'd add this to my MOST DESIRED java feature... GUI be damned...

Mr. Tines

unread,
Feb 20, 1999, 3:00:00 AM2/20/99
to
###

On Thu, 18 Feb 1999 19:19:53 -0800, in
<36CCD859.3DBD@locked_and_loaded.reno.nv.us>
Ken <glockr@locked_and_loaded.reno.nv.us> wrote.....

> What are the chances that Java will some day support non-buffered
> input in non-GUI mode? Sometimes it is very convenient to process
> each character as it's entered, and also convenient to run from a
> command line. Any chance that Sun might agree enough to add a non-
> buffered input stream to java.io.*?

I wouldn't hold my breath on this one - even though the
goal could be achieved simply by wrapping portable 'C'
using just ANSI stdio functions. *sigh*

-- PGPfingerprint: BC01 5527 B493 7C9B 3C54 D1B7 248C 08BC --
_______ {pegwit v8 public key =581cbf05be9899262ab4bb6a08470}
/_ __(_)__ ___ ___ {69c10bcfbca894a5bf8d208d001b829d4d0}
/ / / / _ \/ -_|_-< www.geocities.com/SiliconValley/1394
/_/ /_/_//_/\__/___/@windsong.demon.co.uk PGP key on page

### end pegwit v8 signed text
c0d2a1562badbd318155932f23c1bc08e564b691cd427f90684d82021c64
7f660a2d301ef45295716c767c98659d47c34bae268635cdbeb73d8a3938


Pierre A. von Kaenel

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
This kind of thinking seems counter to the entire OOP philosophy.

Jerry McBride wrote:
>
> In article <7aip8g$sta$1...@node2.nodak.edu>,
> bell...@badlands.NoDak.edu (Brent A Ellingson) wrote:
> >Anyhow, to get you started, there is "JCurses" by Piotr Gucwa, at
> >
>

> If it's not in the JDK, I can't use it.
>

> --
>
> /--------------------\
> | Jerry McBride |
> | mcbr...@erols.com |
> \--------------------/

--
Pierre A. von Kaenel
Math & Computer Science Dept.
Skidmore College
Saratoga Springs, NY 12866

Jerry McBride

unread,
Feb 21, 1999, 3:00:00 AM2/21/99
to
In article <36D03BD2...@skidmore.edu>,

"Pierre A. von Kaenel" <pv...@skidmore.edu> wrote:
>This kind of thinking seems counter to the entire OOP philosophy.
>
>Jerry McBride wrote:
>>
>> In article <7aip8g$sta$1...@node2.nodak.edu>,
>> bell...@badlands.NoDak.edu (Brent A Ellingson) wrote:
>> >Anyhow, to get you started, there is "JCurses" by Piotr Gucwa, at
>> >
>>
>> If it's not in the JDK, I can't use it.
>>

If it's what you're paid to do... it suddenly becomes important. In my case
if it's not available in the jdk or api extentions, it's not wanted.

news.lci.net

unread,
Feb 25, 1999, 3:00:00 AM2/25/99
to
look at System.in

news.lci.net

unread,
Feb 25, 1999, 3:00:00 AM2/25/99
to
look at System.in

0 new messages