Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor
Figure 15.2 Threads of Example 15.1 sleeping and waking up Main Bonnie Clyde Time
public void actionPerformed (ActionEvent event) { x += 9; y += 9; repaint(); } Figure 15.3 Handling a button press to move a ball
public void actionPerformed (ActionEvent event) { for (int i = 0; i < 10; i++) { x += 9; y += 9; repaint(); } Figure 15.4 An attempt to move the ball 10 times with one button press
public void run () { for (int i = 0; i < 10; i++) { x+= 9; y += 9; repaint(); try { Thread.sleep(300); } catch(InterruptedException e) { e.printStackTrace(); } Figure 15.6 The run method of a thread for an animation
Figure The Towers of Hanoi puzzle