Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: My KeyListener is not Working!!

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default My KeyListener is not Working!!

    Okay, i have started my 2d game (im making loads as a exercise - this is my 2nd one...) and i have implented ActionListener on my class and made the actionPerformed class blah blah....

    that is all working but the problem im having is with this...

    I have used addKeyListner(new AL()); in my constructor, then at the bottom of my clas (still inside the paramenter) i have use 'private class AL extends KeyAdapter' and in that class i have used 'keyPressed' and 'keyReleased' methods, but they are not being called when i press a key/....

    ---

    I cant post the code because im on my laptop, although if anyone knows why they may not be called please help out....

    P.S.

    also if anyone can help me out by telling me their Xfire or MSN account and they can help me out through there to fix this problem and a few others i got , that wuld be absolutely great!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: My KeyListener is not Working!!

    The component where the keylistener is installed needs to have focus for the events to be registered. Try calling requestFocus() on the component that you register your key listener with

  3. The Following User Says Thank You to copeg For This Useful Post:

    DarrenReeder (February 28th, 2010)

  4. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: My KeyListener is not Working!!

    haha, i used setFocusable(true); and it is working...thanks!

    Im glad and annoyed...its now 10:00pm on sunday night so thats the whole of weekend wasted because i culdnt fix it over weekend :-(...

    i guess ill spend hour or so on making a game then go bed


    --thanks alot !!

Similar Threads

  1. Working with MAC .DMG files
    By mdv2000 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 21st, 2010, 12:31 PM
  2. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 08:27 PM
  3. Substring program, not working
    By Newoor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 18th, 2009, 12:46 PM
  4. Problem with KeyListener
    By r12ki in forum AWT / Java Swing
    Replies: 3
    Last Post: October 1st, 2009, 01:18 PM
  5. Replies: 4
    Last Post: January 27th, 2009, 12:03 AM