Java Reference
In-Depth Information
Event-Driven Programming
Theprogrammingmodelthatdescribestheinteractionbetweentheappli-
cationandamultitaskingoperatingsystemissometimescalled
event-drivenprogramming
.Theevent-driventermrelatestothefactthat
synchronizationbetweentheoperatingsystemandtheapplicationisinthe
formof
events
.Forexample,
auserevent
takesplacewhentheuseriniti-
atesanactiontochangethesizeoftheprogramwindow.Inresponsetothis
userevent,theoperatingsystemproceedstochangethewindow'ssizeby
meansofasystemevent.Theapplicationisnotifiedofthesystemeventso
thatitcaninitiateadditionalactions.Thisinturngeneratesanotherchain
ofevents.
Theevent-drivenmodelisimplementedbymessagespassedbetween
theapplicationandthesystem.Typicallyeachevent,orgroupofevents,
generatesamessage.Forexample,theuserdragsthecornerofthepro-
gramwindowinordertoresizeit.Thiseventgeneratesamessagethatis
senttotheoperatingsystem.Theoperatingsystemrespondsbyresizing
theapplicationwindow.Ittheninformstheapplicationthatthesizeof
thewindowhaschangedsothattheapplicationcodecanupdatethedis-
playasnecessary.
Figure25-2
showstheactionsandmessagesina
multitasking operating system environment.
...
USER ACTION
control
event
MSG:
update display
system
event
program
event
MSG:
window resized
Figure 25-2 Event-Driven Model