Download presentation
Presentation is loading. Please wait.
1
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
2
Figure 15.2 Threads of Example 15.1 sleeping and waking up Main 1 2 3 4 5 Bonnie 1 2 3 4 5 Clyde 1 2 3 4 5 Time 1 2 3 4 5
3
public void actionPerformed (ActionEvent event) { x += 9; y += 9; repaint(); } Figure 15.3 Handling a button press to move a ball
4
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
5
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
8
Figure 15.13 The Towers of Hanoi puzzle
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.