Results 1 to 4 of 4
Like Tree3Likes
  • 2 Post By Fubarable
  • 1 Post By McDucky

Thread: Need help with KeyListener

  1. #1
    McDucky is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Need help with KeyListener

    I am making an applet game and I want do be able to control a cube using the wasd keys.
    I don't want the KeyListener to be in the Main class but I'm not sure how this is done.
    In my Main class I can add the KeyListener, but if I try to add it in the other class (Player.class) it says "The method addKeyListener is undefined for the type Player".
    Anyone knows why this is?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need help with KeyListener

    If this is a Swing application, then don't use KeyListeners but rather use Key Bindings. You can find a good tutorial via Google and can also find many examples in previous posts in this forum.
    DarrylBurke and McDucky like this.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Need help with KeyListener

    Also, any future Swing related questions that you nay have should be posted in the AWT/Swing section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    McDucky is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Need help with KeyListener

    Thanks for the reply. I will try to use Key Bindings :P
    Fubarable likes this.

Similar Threads

  1. Help with KeyListener
    By armyson in forum New To Java
    Replies: 1
    Last Post: 11-25-2011, 01:56 PM
  2. Help with keylistener?
    By Kaizo in forum New To Java
    Replies: 4
    Last Post: 12-11-2010, 01:55 AM
  3. keyListener not doing anything
    By imorio in forum AWT / Swing
    Replies: 10
    Last Post: 08-17-2010, 11:46 PM
  4. KeyListener - Is this what I need?
    By dbashby in forum New To Java
    Replies: 26
    Last Post: 04-18-2009, 05:14 PM
  5. KeyListener Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:46 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
  •