I know this is a Greenfoot forum, but it is the only java forum I know with quick responses and nice people. I'm trying to code some programs in java without Greenfoot. So I have downloaded eclipse and made some simple console programs just printing out stuff. I have also programmed a puzzle game like my Simple Puzzle Game just way simpler. My problem is that the only way I can get the keys pressed is by placing a TextField object and having focus on that. That part of my code looks like this:
textField.requestFocus(); is placed in the public void paint(Graphics) method.
I have implemented the keyPressed(KeyEvent), keyTyped(KeyEvent) and keyReleased(KeyEvent). Again is there a way to get pressed keys without the need to place a TextField object in the applet?
public class Puzzle extends Applet implements KeyListener { TextField textField; public void init() { textField = new TextField("Random Text"); this.add(textField, BorderLayout.SOUTH); textField.addKeyListener(this); } }