Chapter 12. 11 widgets, events, and emergent behavior: Getting Interactive

Image
Figure 12-1. This is a hardcore programming chapter. Work hard, get sleep, drink water, have patience, stick with it—you’ll come out the other side having unlocked the next level!

You’ve certainly written some graphical applications, but you haven’t created a real user interface yet. That is, you haven’t written anything that lets the user interact with a graphical user interface (otherwise known as a GUI). To do that you need to adopt a new way of thinking about how a program executes, one that is more reactive. Wait, did the user just click on that button? Your code better know how to react and what to do next. Coding for interfaces is quite different from the typical procedural method we’ve been using, and it requires a different way of thinking about the problem. In this chapter you’re going to write your first real GUI, and no, we’re not going to write a simple to-do list manager or height/weight calculator, we’re going to do something far more interesting. We’re going to write an artificial life simulator with emergent behavior. What does that mean? Well, turn the page to find out.

Note

Pronounce GUI like “gooey.”

Get Head First Learn to Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.