B
B
Brodyaga2010-11-27 14:47:49
Java
Brodyaga, 2010-11-27 14:47:49

Java: time to think

Welcome all.
I have never written in Java before, and then I needed to write a testing system. Actually, the only problem that has arisen is that
1) you need to display a question
2) give the user five seconds to answer
3) if the user has entered a number during this time, immediately go to the next question
4) if he has not entered, the program should understand that no answer was given was and move on to the next question.
I read the responses with Scanner, and I can't figure out how to get around the fact that it blocks the stream on commands like next*() and hasNext*() until a newline character is received. I ask java professionals to help :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kekekeks, 2010-11-27
@kekekeks

Have you tried putting it in a separate thread?
I don’t write in Java, I passed by

S
Stepuk, 2010-11-27
@Stepuk

Try using a timer. It runs on a background thread by default.
download.oracle.com/javase/6/docs/api/java/util/Timer.html

A
apangin, 2010-11-27
@apangin

Java has nothing to do with it, these are the features of console I / O.
You will run into the same problem if you start using scanf, fread, etc. in C++, PHP and many other languages.
If you want to get a normal user interface, go straight to the GUI toolkits: AWT, Swing or SWT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question