?
Solved

Is Java well-suited for this?

Posted on 2004-09-09
9
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

801 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