new way to get user name You should use keyTyped() method together with KeyEvent.getKeyChar() instead of keyPressed()/keyReleased() for character input. Your approach has also other problems such as not handling backspace. However you need to edit your question to contain an actual game development related question for a real problem or it probably will be closed.