SPEAKER 1:Let's write a program with a graphical user interface that includes
a window and a button there in.
Let's get started.
>> First, let me go ahead and declare a g window, calling the variable window.
And assign to it, the return value of new g window.
Which will instantiate our window.
And then we specify a width of 320 pixels, and the height of 240 pixel.
Somewhat arbitrarily, but small enough to fit on the screen.
Let's now instantiate a g button.
Not only with a label that the user will see, but also with a unique
identifier.
A so-called action command, that will indeed uniquely identify that button.
g button, button, gets the return value of new g button.
And it's a label shall be, quite simply, button.
And then let's set action command, passing in that button and a unique,
and some what arbitrary word, click.
Let's now add the button to a region of the window, bypassing in window,
and the button, and an identifier for the southern region of the window--
that according to the Stanford portable library, is the lower portion
of the screen.
>> And now let's deliberately induce an infinite loop.
Inside of this loop we're going to listen for two things.
One, whether the user has chosen to close the window.
And two, whether or not the user has clicked on that specific button.
First, we're going to declare a g action event, calling
the variable event.
And assign to it, the return value of wait for event, action event.
>> And now let's check if that event is the closing of a window.
If, get, event, type, passing an event, equals, equals, window
underscore closed.
A special constant declared in the Stanford portable library that
represents exactly that, the closing of a window.
Then I'm going to break out of this otherwise infinite loop, so that we
reach the end of the function.
Otherwise, I'm going to check if string compare of get, action,
command, passing an event, comma, quote unquote, click-- that unique
identifier from before--
equals, equals, zero.
Then, I'm going to print out something arbitrary, like button was clicked.
>> In other words, if upon hearing that a button was clicked, and that event
indicates that the button was clicked was the one with the unique identifier
of quote unquote click, then I want to report as much on the screen.
Now in this case, I only have one button.
But just in case my application had multiple buttons, this technique would
allow me to distinguish among those several buttons.
Outside of this loop, now, I'm going to proceed to close g window, passing
in window as its argument, and then return zero.
>> Let's now save, compile, and run this program.
Make button, dot slash button.
There's my window, there's the button.
Let's go ahead and click on the button.
And the button was clicked.
Let's click on that again.
Button was clicked.
>> Let's now click on the x in the top right hand corner to close the window,
and we break out of that loop and we return zero.