Results 1 to 2 of 2
  1. #1
    codeRunner1 is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default Help with KeyListener in Java Swing

    Hello all. I'm pretty new to Java and I've been struggling trying to wrap my head around some of the aspects of Swing. I'm trying to solve the following problem for an online course I'm taking, any help/advice would be appreciated, thanks! :-)

    "Write a Swing component KeyEcho that listens to its key events with an inner KeyListener. Make it so that whenever a key is pressed, the keyPressed method asks the parameter KeyEvent object for the key char and key code, and outputs them on the console. To make it so that your component can gain focus, put the statements this.setFocusable(true); and this.requestFocus(); in the constructor of your class. Write a main method in your class to try it out."

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    So what is your specific question? Since all we have is your assignment, all we can do at this time is advise you to check out the Swing tutorials on key listeners which you can find here: Key Listeners

    If you have more specific questions after reading this and after attempting to solve it, please feel free to post your code and ask your question.

    Best of luck.

Similar Threads

  1. Help with keylistener?
    By Kaizo in forum New To Java
    Replies: 4
    Last Post: 12-11-2010, 01:55 AM
  2. keyListener not doing anything
    By imorio in forum AWT / Swing
    Replies: 10
    Last Post: 08-17-2010, 11:46 PM
  3. KeyListener - Is this what I need?
    By dbashby in forum New To Java
    Replies: 26
    Last Post: 04-18-2009, 05:14 PM
  4. KeyListener Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:46 PM
  5. how to add a KeyListener
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts