java key-events problem
i have to do a simple animation, where the user intaracts by pressing some keys (up, down, left, right) and a ball moves on the screen.
i made a class like: "class MoveBall extends Frame implements KeyListener, Runnable", with all the functions so i can move the ball in all 4 directions, but what i really want to do is to press 2 keys at the same time (like "up"+"right") and the ball should move diagonally right and up, which doesn't happen... if i press 2 keys, the ball moves either up, either right, depending which i pressed last.
i guess the application can handle only one function at a time (keyPressed or keyTyped).. i mean, if i press a key, i have to lift it and press another to execute the functions again.. but i really don't know
can anybody help me with at least a general idea? or an example would be very useful (what i found on the net were just simple animation with no complicated user interference..)
but what if i have 2 balls, and i want one to move up, and the other to move right, isn't there any specific solution for something like this?
one of my initial ideas was to somehow combine 2 threads.. one was to listen if a key was pressed, the other the same.. but i have no clue where to begin
I found this link that shows how to map keystrokes directly to actions
Last Post: 11-07-2005, 04:00 AM
By Mike Tsakiris in forum .NET
Last Post: 10-04-2002, 05:32 PM
Last Post: 05-03-2002, 04:43 AM
By Glen Kunene in forum Talk to the Editors
Last Post: 03-23-2002, 12:43 AM
By Eyup Gurel in forum Security
Last Post: 01-24-2001, 06:12 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center