starting from the ground up on a project for university, but i need to start with a keyListener, which i just cant get to work...
heres the demo i have put together of a key listener...
i get the following error :
"addKeyListener(java.awt.event.KeyListener) in java.awt.Component cannot be applied to ()..."
i really need help with this... thanks in advanceCode:import java.awt.event.*; import javax.swing.*; public class keyListenerDemo implements KeyListener { public static void main(String [] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createGUI(); } }); } public static void createGUI() { JFrame frame = new JFrame("hello"); frame.addKeyListener(this); //ERROR ON THIS LINE! frame.setSize(700,700); frame.setVisible(true); } public void keyTyped(KeyEvent e) { System.out.println("got here"); } public void keyPressed(KeyEvent e) { System.out.println("got here"); } public void keyReleased(KeyEvent e) { System.out.println("got here"); } }![]()




Reply With Quote