0

Using KeyListeners

I am trying to use the java awt KeyListener and I can't get it to work. Every tutorial that I watch all use the graphics system for jframes. How can I use the normal KeyListener without this?

18th May 2020, 3:13 AM
BendedWills
BendedWills - avatar
1 Antwort
+ 1
*CODE NOT TESTED* this is the way i use keyListener... ______________________________________________ TextArea area = new TextArea(); area.setKeyListener(new HotKeys()); class HotKeys() implements KeyListener { @Override public void keyPressed(KeyEvent e){ int key = e.getKeyCode(); if(key == KeyEvent.VK_SPACE){ System.out.println("space pressed"); } } } _____________________________________
18th May 2020, 3:35 AM
KingDaniel2004
KingDaniel2004 - avatar