I have a JFrame to which I have added JButtons.
win=new JFrame("MyFrame"); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.setBounds(400,200,335,630);win.setResizable(false); win.setFocusable(true); Container c=win.getContentPane(); c.setBackground(Color.black);c.setFocusable(true); btnA = new JButton("A"); btnA.setForeground(Color.white); btnA.setBackground(Color.black); c.add(btnA);
Where do I add the KeyListener to? win or c? I've tried both and the code never calls keyPressed(), keyReleased() or keyTyped()...
Any ideas on what I'm doing wrong?