Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > While(UserInput != 'S') without stopping the execution.

Reply
Thread Tools

While(UserInput != 'S') without stopping the execution.

 
 
joealey2003@yahoo.com
Guest
Posts: n/a
 
      10-01-2005

Hi all.

Every time you call a inputstream.read(), it stops the execution and
wait for the user input. How can i keep it running and check if the
user has typed something?

I tried :

if (System.in.available() > 0) but i need to read to change the
available value....

How can i do that?
I need something like a main loop control:

while(UserInputChar != 'S'){
//RUN
Thread.currentThread.sleep(5000);
}
//----------------------------------------------

Thanks.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On 30 Sep 2005 23:28:33 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote or quoted :

> Every time you call a inputstream.read(), it stops the execution and
>wait for the user input. How can i keep it running and check if the
>user has typed something?


That is exactly what it is doing already.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On 30 Sep 2005 23:28:33 -0700, (E-Mail Removed) wrote or quoted :

>
> while(UserInputChar != 'S'){
> //RUN
> Thread.currentThread.sleep(5000);


Java does not work that way. There is no such thing as single char
input. And readln blocks (waits) all my itself for some input. It
does not return to you until it has a line.

You are coding this as if it were Forth.

for samples of i/o see http://mindprod.com/applets/fileio.html

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
joealey2003@yahoo.com
Guest
Posts: n/a
 
      10-01-2005
but it will stop the execution....
i need to continue if the user has not typed nothing...

while(UserInputChar != 'S'){
Thread.currentThread.sleep(5000);
UserInputChar = System.read //<<<-- Don't stop if there
is nothing typed already...
}
//----------------------------------------------

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On 30 Sep 2005 23:47:52 -0700, (E-Mail Removed) wrote or quoted :

>but it will stop the execution....
>i need to continue if the user has not typed nothing...


there are no console i/o commands to do that. This is not C or
Assembler. Some platforms have no single char i/o, so Java being
multiplatform does not support it. To get those sorts of effects you
need to write a GUI where people type code into boxes while the
program continues in the background and gets interrupted with events
to let it know of changes to the values.

It seems like the most incredible song and dance to do what you want,
but once you get the hang of it you can know out the reams of
necessary bubblegum.

Search the web for some source code using TextField or JTextField. All
you need is a minimal Frame and TextField. I have a number of applets
with source posted at
http://mindprod.com/jgloss/applets/amanuenses.html

many have a TextField, TextArea, JTextField or JTextArea. The problem
is they might do too many other things that would be confusing.

Perhaps Sun's tutorial might have some suitably stripped down code to
show you how to do a TextField.

Any intro to AWT or Swing text will show you how to do this.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
joealey2003@yahoo.com
Guest
Posts: n/a
 
      10-01-2005
but it will stop the execution....
i need to continue if the user has not typed nothing...

while(UserInputChar != 'S'){
Thread.currentThread.sleep(5000);
UserInputChar = System.read //<<<-- Don't stop if there
is nothing typed already...
}
//----------------------------------------------

 
Reply With Quote
 
joealey2003@yahoo.com
Guest
Posts: n/a
 
      10-01-2005
thanks, but the link
http://mindprod.com/jgloss/applets/amanuenses.html
returns 404

 
Reply With Quote
 
joealey2003@yahoo.com
Guest
Posts: n/a
 
      10-01-2005
ops... error ocurred...

the link'

http://mindprod.com/jgloss/applets/amanuenses.html

returns 404

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-01-2005
On 1 Oct 2005 00:06:02 -0700, (E-Mail Removed) wrote or quoted :

>thanks, but the link
> http://mindprod.com/jgloss/applets/amanuenses.html
>returns 404


Oh dear, now I am making the opposite error from my usual one.

http://mindprod.com/applets/amanuenses.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      10-01-2005
(E-Mail Removed) writes:

> but it will stop the execution....


.... of that particular thread. There's a hint right there.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stopping WCZ in command line =?Utf-8?B?amlqaW5tYWNoaW5h?= Wireless Networking 7 09-21-2005 05:45 PM
Want XP Pro to boot up without entering passwords or stopping until it reaches the desktop. William Pierce Computer Support 2 01-24-2005 09:33 PM
How do I unload/replace dll without stopping server? Larry Woods ASP General 10 07-08-2004 05:19 AM
Shell calls without stopping the calling programme Pekka Jarvela C++ 9 05-05-2004 05:30 AM
Stopping long text submissions without spaces Boolean Javascript 2 02-01-2004 03:40 PM



Advertisments