Solved

Is Java well-suited for this?

Posted on 2004-09-09
9
173 Views
Last Modified: 2010-05-18
Hi.  I am looking to write a program that displays a small square in the middle of a black screen.  Every 10 ms, a new calculation is made based on the current position/speed/acceleration of the cursor and some random numbers.  Also (and this is the part I am concerned about) is that keyboard input needs to be taken into consideration.  A simple key was pressed event is not sufficient, as I need to know every 10ms whether zero, one or both of the designated keys are depressed during that interval.   The question is can this be done in Java (both the 10ms period for input and calculation as well as keyboard scanning in this way)?

Thanks a lot for any help you can give (I realise that this would be dependent on the speed of the computer of course).

powertrain
0
Comment
Question by:powertrain
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12020127
Yes you can do that

Swings, Events,Threads and Times will help u to do that

Regards
Sudhakar
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12020198
0
 

Author Comment

by:powertrain
ID: 12020679
Well my question was intending to be a little more specific, maybe a code fragment on the 10ms timing issue and keyboard detection would be more helpful.  That would give me some tangible code upon which to base my decision re: using Java.

Thanks.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12024214
I don't know who your customer is, but if this is for scientific purposes,
e.g. University work, you may run into problems.
I have worked for 6 years at the Amsterdam University, Psychology Dpt.
to program things like these and beware that in many cases
the presentation hardware is not good enough.
Sometimes you must fall back on assembler because of timing.
Of course JAVA can handle mSec events, but with what latency?
Maybe you must write a driver to keep the errors < 0.1 %

The best for these experiments is a standalone LINUX system
with ANSI C only.

;JOOP!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Dave_Toland
ID: 12027403
another consideration is flash, it has a high powered animation engine and has been used to produce effects like this for some years. check out flashkit.com, moock.org, acionscripts.org or were-here.com
0
 
LVL 2

Expert Comment

by:SaMuEl
ID: 12032205
It'd be much easier to code it in Visual Basic.
It has everything you need there, and ready to go
i.e.
Timer
Shape You can draw the square on screen
Mousemove event
Keydown event
Keyup event
KeyPress event

etc...
I'm not sure about the 10ms thing though,  VB can be a bit slow.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12033893
Forget about VB, only C# and C are fast enough for experiments.

;JOOP!
0
 

Accepted Solution

by:
pjnola earned 50 total points
ID: 12035568
The keyboard scanning is not a problem, but I am not sure that you will easily meet the 10ms requirement because of the resolution of timers in Java.  There is even a bug report about this (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4423429).  
This article (http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html) disusses some of the issues.  To summarize: the resolution of System.currentTimeMillis() varies from good (1ms on Linux) to coarse (10ms on Windows) to awful (50ms on Win98).  Strictly speaking, you would be using Object.wait(long millis) rather than System.currentTimeMillis(), but I doubt you would get the precision you want out of that, either.

The JavaWorld article also presents a Timer class that uses native calls to offer good precision, but I'm not sure if that would take care of any issues with Object.wait(millis).
0
 

Author Comment

by:powertrain
ID: 12086625
The last answer was really was I was looking for:  Exaplanation of timing in Java with code samples, as well as some advanced techniques on timing.  It was the most useful of the responses to what I wanted.  Thanks to everone else for assistance too
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now