Simplify the code using KeyAdapter instead of KeyListener method