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."