![]() |
|
API >> Tutorials >> Interfacing Genuts Framework and Java API >>Controlling a sprite with the keyboard
Controlling a sprite with the keyboardJava AWT API offers events to catch keyboard actions, mouse actions, and so on…We will see now how to interface them with the Genuts Framework.
Interfacing events principlesAWT events are processed in their own thread; therefore, we have to be cautious.To avoid conflicts between Genuts thread and AWT events, we have to change only states of our objects, and not to move or resize them somewhere else than in playfield's ticks.
Now the question is: where is the right place of the event listener?
Keyboard eventsIn this section, we will use keyboard events to switch the TimeWrapper between hours display and date display. We will explain the simplest way to process with events.
The KeyListener is implemented directly in the Applet object: KeyTimeApplet.
And we only have to associate the KeyListener to the playfield:
In
Now what about mouse events?
API >> Tutorials >> Interfacing Genuts Framework and Java API >>Controlling a sprite with the keyboard
|