Lesson 9:


Threads -
A thread is an independent sequence of actions in a program.  A java program can have several threads executing at the same time.

  1. The execution of a thread is started with the start() method.
  2. All threads should include calls to the sleep(long ms) or yield() which allows the thread to yield control to another thread.

Try this:

  1. Take a look at the file Bounce1.java from the web page.  Before you try it out BEWARE -- it is going to misbehave and you may need to go into the Task Manager to manually kill it.  Why does this happen?
  2. Take a look at the file Bounce2.java from the web page.  Try it out. 
  3. Change the code so that the start/stop button controls three balls, of different colors, rather than just one ball.
  4. Add a button to add additional balls (up to 100, total).  Each press of this button adds one ball.  All balls should be stopped and removed when the stop button is pressed.  The start button continues to start a single bouncing ball.