Giving up control - Event-driven programming.
The GUI programming style is referred to as
event-driven programming. In this style of programming
you set up the graphical user interface and initialize things.
It appears that the program just stops and sits there doing nothing!
There is no input loop; your program isn't trying to read from the user.
You, the programmer, have to learn to give up control in two ways.
Your program gives control to the GUI system, and you only get control
back to when your listeners are called.
At an even higher level, your program has given control to the user.
It's the user who selects which of your methods to call by their choice
of buttons to click on, menu items to select, etc.
Listeners.
When the user clicks a button
(or uses another GUI component), an event is sent to listener method.
Your job as a programmer is to write a listener method for each
component.
It's the user, not the programmer, who has control, indirectly choosing methods in your program to execute
by interacting with graphical user interface components.