How do I add key listener event handler to JTextField?

In this small swing example we demonstrate how to use KeyAdapter class to handle keyboard event for the text field component to change the text-field’s text to uppercase.