Results 1 to 2 of 2
- 02-28-2011, 12:42 AM #1Member
- Join Date
- Feb 2011
- Rep Power
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."
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.
- By Kaizo in forum New To JavaReplies: 4Last Post: 12-11-2010, 01:55 AM
- By imorio in forum AWT / SwingReplies: 10Last Post: 08-17-2010, 10:46 PM
- By dbashby in forum New To JavaReplies: 26Last Post: 04-18-2009, 04:14 PM
- By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 04:46 PM
- By leonard in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:44 PM