Hacking on Son of Silly Balls - 2

The button still doesn't do anything. Are you surprised? Here's a really important point, which may not be obvious if you're a novice programmer. The name of the button (or the name of a variable in a program) doesn't make any difference to the computer. You could give the button the title "grbxzvlit" and it would do the same. It wouldn't be a good idea, because your users wouldn't have any idea what the button was for, and neither would you in a few weeks -- so, as the commercial says, "Not that you would, but you could."

How do we make it do something? This is one of the most basic things to learn about Interface Builder, so pay attention.

Firstly, we know that there is some way to make the program stop. There's a menu item that does it. The program knows how to do it, and the user interface knows how to get the idea across to the program. We need to track that down.


1. Double-click on the Main Menu icon in the MainMenu.nib window.
2. In the little menu that pops up, click on the apple to bring up the application menu.
3. In the application menu, click on the Quit item. That's what we're trying to track down.
4. Make sure "Connections" is selected in the popup menu of the info box. When you select it, you should see something like what's in the picture. If "target" under "outlets" isn't selected, click on it.
5. Click on "target" at the bottom.
6. See this light blue line connecting the menu item to the First Responder, whatever that means? We've tracked down how the menu tells the program to quit.

The First Responder is the part of the program that gets the first chance to respond to user input. In general, it will do all the things that every program does, like quit. It won't necessarily do the things that are special to this one program. But the light blue line connecting the menu item to the First Responder shows that it's the part of the program that controls quitting. It shows that the menu item will send a message to the FirstResponder. Look over in the info box. See where it says "FirstResponder.terminate:" ? That says that when you select the "Quit" menu item, it will send a "terminate" message to the FirstResponder. The FirstResponder will take care of getting the program to quit.

So what do we need to do with our button? Right! We need to get it to send a "terminate" message to the FirstResponder.


1,2. Control-drag a line from the button to the FirstResponder icon. I've moved my windows around so they're close and I can fit them all in a smallish picture. Don't worry about dragging your line around a square corner. You can draw as crooked a line as you want, and the computer will draw a straight one with a square corner. This isn't a drawing program.
3. Click on "target" under outlets in the info box (make sure "Connections is selected). There are several things a button can do besides send a message. "Target" means "send this message when you're clicked", at least that what it means for a button.
4. Scroll the right-hand side down until you find "terminate". Click on it.
5. Click on "Connect" at the bottom. Save the interface. Build and run the program. Yeehah!

Home       Back       Next