Graphics Reference
In-Depth Information
1.6
The Event-Driven Ball-Shooting Program
In Section 1.1, we began developing a control-driven programming solution to the
ball-shooting program based on verbalizing the conditions (controls) under which
the appropriate actions should be taken:
while favorable condition, parse the input
...
As we have seen, with appropriate modifications, we were able to detail the con-
trol structures for our solution.
From the discussion in Section 1.2, we see that to design an event-driven
programming solution, we must
• define the application state;
• describe how user actions change the application state;
• map the user actions to events that the GUI system supports;
• register corresponding event service routines to service the user actions.
The specification from p. 10 detailed the behaviors of our ball-shooting program.
The description is based on actions performed on familiar input devices (e.g.,
slider bars and mouse). These actions change the application state and thus the
appearance of the application window. This specification describes the second and
third items from the above list without explicitly defining the application state.
Our job in designing a solution is to derive the implicitly defined application state
and design the appropriate service routines.
Listing 1.7 presents our event-driven programming solution. As expected, the
application state (A1) is defined in SystemInitialization() .The AllWorld
Balls set and HeroBall can be derived from the specification on p. 10. The
DefiningNewHeroBall flag is a transient (temporary) application state designed
to support user actions across multiple events (click-and-drag). Using transient
application states is a common approach to support consecutive interrelated events.
Listing 1.7 shows the registration of three types of service routines (A2):
1. user-generated application-specific events (A2S1);
2. an application-defined event (A2S2);
3. a GUI system-generated event requesting collaboration (A2S3).
Search WWH ::




Custom Search