java key-events problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: java key-events problem

  1. #1
    Join Date
    Dec 2005
    Posts
    2

    Arrow java key-events problem

    hello everybody.
    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..)
    thanks all.

  2. #2
    Join Date
    Dec 2005
    Posts
    2
    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

  3. #3
    Join Date
    Oct 2005
    Posts
    107
    http://forum.java.sun.com/thread.jsp...sageID=3510030

    I found this link that shows how to map keystrokes directly to actions

Similar Threads

  1. Replies: 2
    Last Post: 11-07-2005, 04:00 AM
  2. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  3. Replies: 1
    Last Post: 05-03-2002, 04:43 AM
  4. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 12:43 AM
  5. asymetric encryption with private key
    By Eyup Gurel in forum Security
    Replies: 9
    Last Post: 01-24-2001, 06:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center