Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Quick newbie Java programming question (idle, timers) (http://www.velocityreviews.com/forums/t128973-quick-newbie-java-programming-question-idle-timers.html)

Starwynd 11-22-2003 11:59 PM

Quick newbie Java programming question (idle, timers)
 
Greetings all -

I am working on programming a very very simple java application for
fun - I am still learning java, and was curious of the best way to
accomplish the following task -

I want to be able to have my Java program run, and have the user be
able to exit it at any time by typing an exit string ("exit") or
something of like. But also, I have other things running on timers in
the backgrounds - it's kind of a virtual reality game. While the game
is running, I want it to update onscreen with different messages, such
as "it is now evening" or "it is now noon", but still be able to
accept user input at any time to terminate the program. I tried adding
the system.exit(0) line to my timer such as this:

import java.util.*;
import java.io.*;


public class ShortSnowUpdate extends TimerTask
{
public ShortSnowUpdate()
{
}
public void run()
{
if (KeyboardReader.readInt() != 5)
{
System.out.println("it is snowing");
}
else
System.exit(0);



}

}


But this just sits there at the command prompt always waiting for user
input, and not actually processing the update when it occurs once a
minute (the timer event is scheduled in the manager thread to run once
a minute, and display the message "it is snowing" to the screen). It
obviously exits nicely when "5" is pressed, but it won't continue to
give me the "it is snowing" message once a minute. I just need
something that will let the program idle while responding to the
timers, but also ending if the user inputs the end input (5 in this
case) while not constantly prompting the user to enter something.Any
ideas? I know this is probably something pretty simple! :)

-Starwynd

Tor Iver Wilhelmsen 11-23-2003 09:10 AM

Re: Quick newbie Java programming question (idle, timers)
 
skwsurvey@juno.com (Starwynd) writes:

> if (KeyboardReader.readInt() != 5)


Most likely, this is a blocking call. You need to put the message into
a separate thread from the one you use to read the keyboard.


All times are GMT. The time now is 05:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.