Solved

Is Java well-suited for this?

Posted on 2004-09-09
9
172 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:powertrain
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:Dave_Toland
Comment Utility
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
Comment Utility
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
Comment Utility
Forget about VB, only C# and C are fast enough for experiments.

;JOOP!
0
 

Accepted Solution

by:
pjnola earned 50 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 69
wordappend challenge 8 84
Unexpected HttpURLConnection connection behavior 2 46
Java / Linux and Regular Expressions 11 43
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

18 Experts available now in Live!

Get 1:1 Help Now