Timing
To do animation or anything that requires delay, you need to implement
the class runnable. The code is a little complex; it uses something
called threads to delay operating. You dont need to understand the
code. All you need to do is implement runnable in your code decleration,
and include the code below the **********************.
- The only editable section of that code is the int delay which
is in millliseconds.
- When the applet is run, the delay is started automatically and
paint is called every 50 milliseconds.
- To stop the applet, call the method stop()
Assignment:
- Add code so that every 40 times it moves the color changes between green and red.
- Add code so that when they press 1-3 the animation changes speed. (change the delay - which already is a global variable)
- You will need to add the keylistener stuff. (implement runnable, KeyListener (remember to have nec. imports and init statement).
- Add code so when space bar is pressed the animation starts and
stops.
|