Event-driven programming

Programmers coming from a text console world may find GUI programming a bit strange at first. In "traditional" programming, the program guides the user through several screens of prompts and options, and the program is always in control of what is going to happen next.

In GUI-land, you mostly give up the control flow of your programs and let the system drive them for you. It is the user who is in control now — every time the program is run, the user may choose a different way to work his way through the user interface. Menu options may be invoked at any time, and windows may be opened and closed at will.

GUI programming generally operates on an event-driven model. This means that applications get events from the system or the user and must react to them. This is different from the "traditional" model where the program tells the user what to do next at every step.

Event-driven programs typically sit around in a loop waiting for events to come. When an event is received, the program figures out what to do with it and proceeds accordingly. An event could be "the user pressed a mouse button", or "a window moved", or even "you must terminate yourself".