Solved

Is Java well-suited for this?

Posted on 2004-09-09
9
177 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 41
jboss wildfly 10.1 10 419
Android development question 2 78
Coding for the first time 9 65
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

756 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