Solved

Is Java well-suited for this?

Posted on 2004-09-09
9
175 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where to store the queries for modification of table 4 62
javap not working 8 46
expectj telnet failing 5 36
hibernate example for saving data 19 42
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

777 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