Docsity

Threads and GUIs in CS251 Intermediate Programming - Prof. Douglas J. Wokoun, Assignments of Computer Science

Partial preview of the text

Download Threads and GUIs in CS251 Intermediate Programming - Prof. Douglas J. Wokoun and more Assignments Computer Science in PDF only on Docsity!

CS251 Intermediate Programming

Lecture 27

Threads

  • Final Monday, December 15 at noon.• Homework 6 due today.• GUIs and Threads lab• GUIs and Threads lecture• Review Questions• Quiz feedback• ICES formsAgenda:

synchronization issues in GUI code.There is only one event thread to avoid dealing withfunctions: event delivery, screen repainting, etc.The AWT maintains a separate thread for all GUI-related

non-CS types who wouldThe assumption is GUIs are programmed by graphic artists/

fi nd multi-threading too complex.

thread synchronization.multi-user requirements require advanced knowledge ofThe CS types would be assigned server-side work where

the event thread.(computation, I/O, etc.) must be done on a thread other than Any method that could take a long time to executeresponsive.painting to freeze and all GUI widgets to become non-prevents other events from being dispatched. This causes allAny long computation inside an event listener or paint method

Improve the threading behavior of a class:

Download the application class

(^) ThreadTest.java

(^) from the web site.

Observe how clicking either button freezes the animation.

Create a new thread class to process the call to

(^) button2Work()

.

Change

(^) button2()

(^) to create the new thread instead of calling

button2Work()

(^) directly from the event thread.

Have the new thread finish by kicking off a

(^) Runnable

(^) that restores

Button 2 to enabled status.