Re: The use of KeyListeners to make an object move in Applet
Posted By:
Robert_Lybarger
Posted On:
Tuesday, May 30, 2006 08:35 PM
Been a long while since I've done applets, but you don't need the keyEvent method to necessarily have anything to do with run(). Treat the combination of the init() and run() method like a sort of main() method in a normal program. When the keyEvent is processed, decide which key was used, increment your location for the object, and then just trigger a repaint. The run() method doesn't need to be really involved in the event handling code.